|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <iostream>
#include <fstream>
struct FishOil
{
std::string name;
std::string uid;
char sex;
};
bool InitFishC();
bool ReadFishC();
void RecordFishC();
bool WriteFishC(FishOil *OilData);
int main()
{
int i;
InitFishC();
while( 1 )
{
std::cout << "请选择需要进行的操作: \n";
std::cout << "1. 打印数据到屏幕\n";
std::cout << "2. 录入数据\n";
std::cout << "3. 退出程序\n";
std::cin >> i;
switch( i )
{
case 1:
if( ReadFishC() )
std::cout << "成功读取文件^_^\n\n";
else
std::cout << "读取文件失败T_T\n\n";
break;
case 2:
RecordFishC();
break;
case 3:
return 0;
}
}
std::cout << "初始化失败T_T......\n\n";
return 0;
}
bool InitFishC()
{
FishOil OilInit;
OilInit.name="小甲鱼";
OilInit.uid="fishc0000";
OilInit.uid='F';
if( WriteFishC(&OilInit)==false )
{
std::cout << "初始化失败 ";
}
}
bool ReadFishC()
{
char ch;
std::ifstream fileinput("FishC.txt",std::ios::in);
std::cout << "名字" << "号码" << "性别" << "\n";
if( fileinput.is_open() )
{
fileinput >> ch;
std::cout << ch <<"\n";
fileinput.close();
}
}
void RecordFishC()
{
char save,start;
FishOil *pointdata;
start = 'Y';
while( 'Y'==start )
{
std::cout << "请输入name ";
std::cin >> (*pointdata).name ;
std::cout << "请输入uid ";
std::cin >> (*pointdata).uid ;
std::cout << "请输入sex ";
std::cin >> (*pointdata).sex ;
std::cout << "录入成功,是否保存Y/N";
std::cin >> save;
if( save=='Y')
{
if(WriteFishC( pointdata ))
std::cout << "成功写入" ;
}
else
std::cout << "失败写入 ";
}
std::cout << "是否再次录入?";
std::cin >> start;
}
bool WriteFishC( FishOil *pOilData )
{
std::ofstream fileOutput("FishC.txt", std::ios::app);
if( fileOutput.is_open() )
{
fileOutput << pOilData->name <<" ";
fileOutput << pOilData->uid <<" ";
fileOutput << pOilData->sex <<"\n";
fileOutput.close();
std::cout << "数据成功保存 ";
}
else
std::cout << "数据保存失败 ";
}
————————————————————————————————————————————————————————————————————————————————————————————————————————————
运行后出现错误:error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no accepta
ble conversion)
不知道什么毛病!!!!!!!!!!!!求帮忙!!!!!!!!!谢谢大家!!!!!!!:dizzy::dizzy: |
|