utab wrote in message
<1142272393.075929.267210@i40g2000cwc.googlegroups .com>...[color=blue]
>Hi there,
>I am trying to read from a file and at the same time change certain
>fields of the same field,[/color]
[snip][color=blue]
>For example, I position my file pointer at the begining of the 4th
>fileld lets say 25th character(3*(field_width)+1) and when I try to
>write to fields 4 5 6 with
>
> inoutFile << setw(8) << setiosflags(ios::right) << "sometext";
> inoutFile << setw(8) << setiosflags(ios::right) << "sometext";
> inoutFile << setw(8) << setiosflags(ios::right) << "sometext";
>
>and then I would like to go to the newline with
>
> inoutFile.ignore(std::numeric_limits<std::streamsi ze>::max(), '\n');
>// go to the newline[/color]
Did you check to see if the stream is still valid?
if( inoutFile ){ /* do something */ }
if( inoutFile.good() ){ /* all is well */ }
if( inoutFile.bad() ){ /* all is NOT well */ }
if( inoutFile.eof() ){ /* you're at end-of-file */ }
if( inoutFile.fail() ){ /* all is NOT well */ }
You are probably truncating the file as soon as you write to it. Then you try
to look for the newline while you are actually at EOF.
See this thread:
From:
ma740988@gmail.com <ma740988@gmail.com>
Newsgroups: alt.comp.lang.learn.c-c++
Date: Sunday, March 05, 2006 5:51 PM
Subject: fstream question
// read file in, modify, write file out.
std::vector<std::string> TheFile;
std::string FileName( "MyFile.txt" );
std::ifstream in( FileName.c_str() );
if(!in){ /* handle error here */ } //if(!in)
for( std::string line; std::getline(in, line); ){
TheFile.push_back(line);
}
in.close();
// modify the strings in 'TheFile'.
std::ofstream out( FileName.c_str() );
if(!out){ /* handle error here */ } //if(!out)
for(std::vector<std::string>::const_iterator w = TheFile.begin();
w != TheFile.end(); ++w){
out << *w << std::endl;
} // for(w)
out.close() // or, let it go out of scope
Is that any help?
--
Bob R
POVrookie