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!
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!
Nothing more to tell about me...
Happy day =)
Code:#include <iostream> #include <string> #include <fstream> using namespace std; int main() { ifstream fin("file.txt"); string s; fin >> s; return 0; }
Detailed understanding of language features - even of all features of a language - cannot compensate for lack of an overall view of the language and the fundamental techniques for using it. - Bjarne Stroustrup
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...
Nothing more to tell about me...
Happy day =)
That method stops at the first space. To get a whole line of input you'll need to use getline.
Code:getline(fin, str);
Detailed understanding of language features - even of all features of a language - cannot compensate for lack of an overall view of the language and the fundamental techniques for using it. - Bjarne Stroustrup
Most perfect!
Thanks!
Nothing more to tell about me...
Happy day =)