The best way to read the file is to use getline():
Code:
std::ifstream in( "myfile.txt" );
if ( in ) {
std::string line;
while( std::getline( in, line ) ) {
std::cout<< line << "\n";
}
}
in.close();
If you're unfamiliar with using 'std::' just ignore them. I prefer not to use "using namespace std;" globally.
A 'problem' arises though when you wish to change the contents of a file. You cannot really simply change a line. You have to read in the whole contents of a file manipulate it and save it to another file and delete the original (so you don't loose data on bad luck). (or read line by line or block by block if the file's large).
You could alternatively look into fstream's rather than ifstreams and ofstreams but maybe get used to them first.