In the following code:
#include <iostream> #include <fstream> #include <string> using namespace std; int main() { string x = "This is C++."; ofstream of("d:/tester.txt"); of << x; of.close(); ifstream read("d:/tester.txt"); read >> x; cout << x << endl ; }
Output :
This
Since the operator reads to the first space, I get this output. How can I extract a string back to a string?
I know this form istream& getline (char* s, streamsize n ); but I want to save it in a string variable. How can i do this?
c ++ string getline ifstream
Suhail Gupta Jul 12 '11 at 10:59 2011-07-12 10:59
source share