1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

eof bit not set

Discussion in 'C++' started by mad_girl, Oct 5, 2007.

  1. mad_girl

    mad_girl New Member

    Joined:
    Aug 14, 2007
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    why such two easy lines don work
    char c;
    while(!file.eof ())
    { file.read(c,1); cout<<c; }
    the loop is infinite i don know why the eof bit is not set or what
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    You don't show how you're opening the file, so the fail bit is probably set, which means the eof bit will not be set. If you care to show some more code, feel free to do so.

    If you show more code, and want a response, put the code in code tags.
     
  3. mad_girl

    mad_girl New Member

    Joined:
    Aug 14, 2007
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    string str2="test.txt";
    ifstream file(str2.c_str (),ios::in);
    and another question please when file.tellg() return -1?
    Code:
    while(file.tellg()<=lastEnd)
    					{
    						file.getline (temp,20,'=');
    			if (strncmp(temp,varName.c_str(),varName.length())==0)
    						{
    							file.getline (X,20);
    							return true;
    						}
    						file.ignore(30,'\n');
    					}
    when i debug this code and make it print lastEnd and file.tellg() values through the iteration of the loop every thing is fine until file.tellg() return -1 in the middle of the file so the loop doesn't end??!!!!!
     
  4. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Are you paying attention, and have you bothered to read the documentation for the functions you use?
     
  5. mad_girl

    mad_girl New Member

    Joined:
    Aug 14, 2007
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    i already did, but i don remember any thing telling me the code i sent is wrong.
    thanks 4 help
     

Share This Page