我一直在想出一个代码,删除保存在文本文件中的数据,但无济于事。应该怎么做?在C++中,这是我的代码我该如何改进它,以便它删除保存的数据可能是条目的入口?如何删除保存在C++文本文件中的数据
#include<iostream>
#include<string>
#include<fstream>
#include<limits>
#include<conio.h>
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.ignore(numeric_limits<streamsize>::max(), '\n');
getline(cin,s1);
wysla<<s1;
wysla.close();
break;
}
return 0;
}
这功课吗?数据是否为 – 2013-04-26 12:55:07
?你是指文本文件中的任意行吗?你不能到位 – sherpya 2013-04-26 12:55:55
只有一种方法可以从文件中间删除。将整个文件读入内存,删除内存中不需要的部分。从内存中写出整个文件。 – john 2013-04-26 12:58:24