簡體   English   中英

我的程序輸入不會保存到文本文件中

[英]My program input wouldn't save into a text file

大家好,我在下面寫的代碼是一個日記項目,它仍處於早期階段,因此在運行它時,它應該告訴您輸入日記條目,然后將其保存在文本中,但未保存在其中。文件請幫忙!!

#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);

除了丹尼爾·A·懷特(Daniel A. White)的答案之外,您可能還會遇到問題,即文件中僅保存了一個單詞。 這是由以下行引起的:

cin>>s1;

你寧可使用

getline(cin, s1);

這里。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM