//你的代码很乱,帮你改好了,比之前好一些,但是还是乱,而且有一些潜在的bug,实现相同的功能我可以全部重写一个更加简洁高效无bug,如果你需要请新开一贴我写给你
#include
#include
#include
using namespace std;
class Song
{
public:
void add();
void display();
void modify();
void empty();
private:
string song[10];
};
void Song::add()
{
ofstream wfile;
wfile.open("mysongs.txt",ios::out);
int i=0;
char c;
while(1&&i!=10)
{
cout<<"name:"<
cout<<"add another?(y or n)"<
while(c!='y'&&c!='n')
{
cout<<"error!choose again:"<
}
wfile<
wfile<
}
wfile.close();
}
void Song :: display()
{
ifstream rfile;
rfile.open("mysongs.txt",ios:: in);
string s;
while(rfile.peek()!=EOF)
{
rfile>>s;
cout<<"name:"<}
rfile.close();
}
void Song::modify()
{
fstream rwfile;
rwfile.open("mysongs.txt");
string s,a;
int len;
cout<<"input the name you want to modify:"<
while(rwfile.peek()!=EOF)
{
rwfile>>a;
len=s.size();
if(0==strcmp(a.c_str(),s.c_str()))
{
rwfile.seekg(-len,ios::cur);
cout<<"find and input new name:"<
a=a+" ";
rwfile< cout<<"modified!"<
return;
}
}
cout<<"no record!"<
void main()
{
Song * p=new(Song);
p->add();
p->modify();
p->display();
cout<