#include <iostream.h>
#include <string.h>
#include <fstream.h>
#include "person.h"char person::showEditChoice()
{
char userinput;
char fileName[80]=" ";
cout << endl;
cout << "==================================\n" << endl;
cout << " 1. 创建并编辑新记录" << endl;
cout << " 2. 查询记录" << endl;
cout << " 3. 显示所有记录" << endl;
cout << " 4. 删除记录" << endl;
cout << " 5. 退出"<<endl;
cout << "===================================\n"<<endl;
cout << "输入对应操作的号码->:";
cin >> userinput;
if(userinput!='5')
{
if(userinput == '1')
cout << "\n创建并编辑新记录:\n" ;
if(userinput == '2')
cout << "\n请输入已有的记录:\n" ;
if(userinput == '4')
cout << "\n请输入删除记录:\n" ;
}
cin.ignore(); //忽略前面的输入
cin.getline(fileName,80);
strcpy(fname, fileName);
return userinput;
}person::adduser()
{
char inputChar; strcat(fname,".dat");
strcpy(fname,"record\\");
ofstream os1(fname); //新建一个文件
os1.close(); fstream fs(fname,ios::in|ios::out); //可读又可写的方式打开文件 cout << "请输入要保存的记录, 如果要结束输入,文件结束符号(CTRL+Z)\n"; while ( ( inputChar = cin.get() ) != EOF )
fs.put(inputChar); if(inputChar == EOF)
cout << "记录已经保存!" << endl;
fs.close( );
}person::finduser()
{
strcat(fname,".dat");
ifstream infile(fname);
if(!infile){
cout << "用户不存在!\n";
}
}
person::deleteuser()
{
char file[80] ="";
strcpy(file,fname);
ifstream infile(fname);
if(infile)
{
unlink(fname);
cout<<"当前用户"<<file<<"已经删除"<<endl;
}
else
{
cout << "用户不存在!";
}
} void main()
{
cout << "-----------------------------------\n" << endl;
cout << " 简单的通信录 " << endl;
cout << " 版本:1.0\n" << endl;
cout << "-----------------------------------\n" << endl;
person instant;
char userinput;
userinput = instant.showEditChoice();
switch(userinput)
{
case '1':
instant.adduser();
break;
case '2':
instant.finduser();
break;
case '3':
cout << "\n显示所有记录:\n" ;
system("dir record/b");
break;
case '4':
instant.deleteuser();
break;
case '5':
return;
}
}
unlink() 和system()
error C2660: 'system' : function does not take 1 parameters
怎么解决!
我在vc++6.0中调试
#include <string.h>
#include <fstream.h>
#include "person.h"char person::showEditChoice()
{
char userinput;
char fileName[80]=" ";
cout << endl;
cout << "==================================\n" << endl;
cout << " 1. 创建并编辑新记录" << endl;
cout << " 2. 查询记录" << endl;
cout << " 3. 显示所有记录" << endl;
cout << " 4. 删除记录" << endl;
cout << " 5. 退出"<<endl;
cout << "===================================\n"<<endl;
cout << "输入对应操作的号码->:";
cin >> userinput;
if(userinput!='5')
{
if(userinput == '1')
cout << "\n创建并编辑新记录:\n" ;
if(userinput == '2')
cout << "\n请输入已有的记录:\n" ;
if(userinput == '4')
cout << "\n请输入删除记录:\n" ;
}
cin.ignore(); //忽略前面的输入
cin.getline(fileName,80);
strcpy(fname, fileName);
return userinput;
}person::adduser()
{
char inputChar; strcat(fname,".dat");
strcpy(fname,"record\\");
ofstream os1(fname); //新建一个文件
os1.close(); fstream fs(fname,ios::in|ios::out); //可读又可写的方式打开文件 cout << "请输入要保存的记录, 如果要结束输入,文件结束符号(CTRL+Z)\n"; while ( ( inputChar = cin.get() ) != EOF )
fs.put(inputChar); if(inputChar == EOF)
cout << "记录已经保存!" << endl;
fs.close( );
}person::finduser()
{
strcat(fname,".dat");
ifstream infile(fname);
if(!infile){
cout << "用户不存在!\n";
}
}
person::deleteuser()
{
char file[80] ="";
strcpy(file,fname);
ifstream infile(fname);
if(infile)
{
unlink(fname);
cout<<"当前用户"<<file<<"已经删除"<<endl;
}
else
{
cout << "用户不存在!";
}
} void main()
{
cout << "-----------------------------------\n" << endl;
cout << " 简单的通信录 " << endl;
cout << " 版本:1.0\n" << endl;
cout << "-----------------------------------\n" << endl;
person instant;
char userinput;
userinput = instant.showEditChoice();
switch(userinput)
{
case '1':
instant.adduser();
break;
case '2':
instant.finduser();
break;
case '3':
cout << "\n显示所有记录:\n" ;
system("dir record/b");
break;
case '4':
instant.deleteuser();
break;
case '5':
return;
}
}
unlink() 和system()
error C2660: 'system' : function does not take 1 parameters
怎么解决!
我在vc++6.0中调试
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货