I'd still like to understand what is going wrong with my code. Any idea?
1 2 3 4 5 6
while(ist)
{
string s;
getline( ist, s, '\n'); // if this fails (say, there are no more lines to get)
ost << s << '\n'; // we still write whatever is in s (s would be empty and an empty line would be written)
}
This would be fine (check for input failure after attempted input):
1 2 3 4 5 6
bool append_file( std::ifstream srce_file, std::ofstream& dest_file )
{
std::string line ;
while( std::getline( srce_file, line ) ) dest_file << line << '\n' ;
return dest_file && srce_file.eof() ;
}
This would be better:
(non-lounge-kiddie like: we know that std::getline() is not the one and only true way of performing robust input):