0
How to copy/read multiple lines using the fstream/ifstream/ofstream?
it only read the first line https://code.sololearn.com/cgE4jUs8kj7h/?ref=app
8 Réponses
+ 1
Did you place cnf<<line<<endl; inside the loop as well?
+ 1
You should put the getline part in a loop to read the entire file. Also, don't close the file before you read everything.
Code Example :
------------------------------------------------------------------
string line;
ofstream cnf("newfile.txt");
while(!readFile.eof())
// While we are not at the end.
{
getline(readFile, line);
cnf <<"Line read from the Good.c file: "
<<line <<endl;
// Read from one and write to other.
}
readFile.close();
cnf.close();
// Close only when done.
+ 1
A loop is required here, as your file contains multiple lines and you need to have a getline for every single one of them.
0
I'll try
0
will a new getline get the line? I'll try
*** edit:
I meant will a newline get the next line
0
I tried it.. but it doesn't read all.. this time it reads only the last line into the new file... but reads all on the console/cmdline
0
no.. I just did that.. thanks it worked