#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
ofstream wysla;
wysla.open("wysla.txt", ios::app);
int kaput;
string s1,s2;
cout<<"Please select from the List below"<<endl;
cout<<"1.New entry"<<endl;
cout<<"2.View Previous Entries"<<endl;
cout<<"3.Delete an entry"<<endl;
cin>>kaput;
switch (kaput)
{
case 1:
cout<<"Dear diary,"<<endl;
getline(cin,s1);
wysla<<s1;
wysla.close();
break;
}
return 0;
}
このコードでは、文字列を保存しようとしましたが、できません。たとえば、getline を使用するとテキスト ファイルに何も保存されず、cin を使用すると最初の単語だけが保存されます。エントリ全体を保存したいのですが、どうすればよいですか?