Hello!
I am currently attempting to read all the lines from a text file, and append them to one long string.
At the moment, it seems that the line that is read in keeps overriding the string, instead of appending it.
I think it has something to do with the newline character within the textfile, but I'm not 100% sure how that is affecting it. Just wondering how I would append the strings to one long one.
Any help would be appreciated,
Thanks!
int main(){
string line,
fullLine;
ifstream in("data.txt");
if(!in){
cerr << "Unable to open file" << endl;
return 1;
}
while(getline(in,line)){
fullLine += line;
}
cout << fullLine << endl;
}
The text file (data.txt) contains :
rachel
hello
goodbye
and the output is:
goodbye