Hi every one i wrote the code below it is of a diary project it is still in the early stages so when you run it its suppose to tell you to enter a diary entry and then save it in a text but it is not being saved in file please help!!
#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;
cin>>s1;
wysla<<s1;
wysla.close();
break;
}
return 0;
}
我想你这里有错字
wysla.open("wysla.txt", ios::app);
In addtion to Daniel A. White's answer you will probably run into the problem, that only one word is saved in your file. This is caused by this line:
cin>>s1;
You should rather use
getline(cin, s1);
here.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.