次のコードでは:
#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 );
いますが、文字列変数に格納したいと思います。
これどうやってするの ?