#include
#include
class Song
{
public:
struct Node
{
char name[10];
};
void add();
void display();
void modify();
void empty();
private:
Node song[10];
};
void Song::add()
{
ofstream wfile;
wfile.open("mysongs.txt",ios::out);
int i=0;
while(1)
{
cout<<"name:\n";
cin>>song[i].name;
wfile<
cout<<"add another?(y or n)\n";
char c;
cin>>c;
while(c!='y'&&c!='n')
{
cout<<"error!choose again:\n";
cin>>c;
}
if(c=='n') break;
i++;
}
wfile.close();
}
void Song :: display()
{
ifstream rfile;
rfile.open("mysongs.txt",ios:: in);
int i=0;
while((!rfile.eof()))
{
rfile>>song[i].name;
i++;
}
for(int j=0;j
}
void Song::modify()
{
ifstream rfile;
rfile.open("mysongs.txt",ios::in);
char s[10],a[10];
int k,x=0,i=0;
cout<<"input the name you want to modify:\n";
cin>>s;
while((!rfile.eof()))
{
rfile>>song[i].name;
i++;
}
for(int j=0;j
if(strcmp(s,song[j].name)==0)
{
cout<<"find and input new name:\n";
cin>>a;
cout<<"modified!\n";
k=j;
x=1;
break;
}
}
strcpy(a,song[k].name);
rfile.close();
ofstream fin("mysongs.txt",ios::out);
for(k=0;k
cout<<"no record!\n";
fin.close();
}
void main()
{
Song * p=new(Song);
p->add();
p->modify();
p->display();
cout<
如题!该程序中,modify函数实现不了我想要的操作。。。
1.能不能在我这个代码的基础上进行修改?
2.能告诉我问题在哪吗?
3.文件读取的数据是存放在哪里的啊?之后怎么处理?我想了解下流程。。。
谢谢!