Thread: getting two extra ?? while reading my input file

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    2

    getting two extra ?? while reading my input file

    hi …


    i am trying to read my input file but i am ending up in two extra "??".

    can you please help me in this to get rid of extra data

    please find my input below:
    1 xy 2
    2 z xy
    5 R 1004 I 5678 E 2000 R 8002 E 7001

    output:
    ??1 xy 2
    2 z xy
    5 R 1004 I 5678 E 2000 R 8002 E 7001


    code:

    insert
    Code:
    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include <map>
    usingnamespacestd;
    
    
    int main() {
        ifstream infile; 
        string fileName,line,word;
        int lineno,wordno,module,i,varcnt,baseaddr[i];
        int get;
    istringstream instr;
        char *worda;
        
    cout << "Enter the name of the file: ";
        cin >> fileName;
        infile.open(fileName.c_str());
        
        lineno=0;
        i=1;
        baseaddr[i]=0;
        
        if (infile.is_open()) 
    
                 {
            while (getline(infile,line))
                      {
                cout << line << endl    
              }
                  }
    else
    cout << "Unable to open file" << endl;
    return0;
        }

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    they're probably not actually question marks. you probably created that file with wordpad or some other text editor that supports an encoding specifier at the beginning of the file. you need to re-save the file in ANSI encoding. that will probably fix your issue.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    2
    Thanks a lot Elkvis.. it worked…

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You need to fix your indentation.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading from an input file
    By Trevers in forum C Programming
    Replies: 1
    Last Post: 05-06-2010, 12:21 PM
  2. Reading Input from file
    By Horox in forum C Programming
    Replies: 2
    Last Post: 01-31-2008, 12:13 AM
  3. One Extra Input
    By swanley007 in forum C++ Programming
    Replies: 6
    Last Post: 11-07-2005, 11:51 AM
  4. EOF reading one more extra
    By keithmolo in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2003, 09:27 AM
  5. reading input file
    By dellebelle751 in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2002, 02:05 PM