-
file io ?
When reading in strings from a file is it alright if the strings are on separate lines? like if i was doing:
string str1, str2, str3;
ifstream file("foobar.txt");
file >> str1 >> str2 >> str3;
cout << str1 << str2 << str3
and foobar.txt reads
stringone stringtwo (a new line)
stringthree
would there be any problem due to the newline?
-
As long as the strings don't have spaces in the middle of them(in your file) it would be ok.
-
I'm not sure what Zen means by spaces in the middle of your strings. That statement is confusing.
The ifstream object uses a get pointer to position the file pointer at the next input location in your file. So, when processing your file sequentially, the get pointer is automatically advanced to the next, sequential data location. White space is ignored, to include '\n'.
hth,
-
ok thanks
thanks, it did work.
and i think he meant that if one of my strings was
"str ing1" it would read in "str" and "ing1" as separate streams.