【发布时间】:2011-10-03 12:52:56
【问题描述】:
在以下代码中:
#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
由于 >> 运算符读取到第一个空格,我得到了这个输出。如何将行提取回字符串?
我知道istream& getline (char* s, streamsize n ); 的这种形式但我想将它存储在字符串变量中。
我该怎么做?
【问题讨论】:
-
也可以在这里查看建议:stackoverflow.com/questions/116951/…
标签: c++ string ifstream getline