How can I read a string(I mean the string class) from a file?
What a shame, such ridiculous question. I tried to find it in my BC++ reference, didnīt find anything...
Thanks any answer!
Printable View
How can I read a string(I mean the string class) from a file?
What a shame, such ridiculous question. I tried to find it in my BC++ reference, didnīt find anything...
Thanks any answer!
Code:#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream fin("file.txt");
string s;
fin >> s;
return 0;
}
Thanks!
I was doing
s << fin;
But one more question, does this read trouhg blank spaces?
For example: as far as I know, cin << s would read characters until Enter is pressed, but would "cut" at the first blank space...
That method stops at the first space. To get a whole line of input you'll need to use getline.
Code:getline(fin, str);
Most perfect!
Thanks!