请问下大家 都用什么编译器 我在用VC6
在学小甲鱼老师的 C++课程看了课件之后编译 报错 查了下百度说是编译器的事 我也不知道是不是编译器的事就想顺着小甲鱼老师的课程走 Visaul Stdio 2017 #include <iostream>#include <fstream>
#include <windows.h> // 为了使用Sleep()函数
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 = {"小甲鱼", "fishc00001", 'M'};
if( WriteFishC(&OilInit) == false )
std::cout << "初始化失败T_T\n";
}
bool ReadFishC()
{
std::string temp;
std::ifstream fileInput("FishC.txt");
if( fileInput.is_open() )
{
std::cout << "\n正在输出记录数据...... ";
for( int i=0; i <= 100; i++ ) // 打印百分比
{
std::cout.width(3);
std::cout << i << "%";
Sleep(50);
std::cout << "\b\b\b\b";
}
std::cout << "\n\n";
std::cout << " 姓名 " << "身份证" << " 性别 " << "\n\n";
while( std::getline( fileInput, temp ) )
{
std::cout << temp << " ";
std::cout << "\n";
}
std::cout << "\n\n";
return true;
}
else
return false;
}
void RecordFishC()
{
char goon, Save;
FishOil OilData;
FishOil *pOilData;
goon = 'Y';
while( 'Y' == goon )
{
std::cout << "请输入鱼C账号: ";
std::cin >> OilData.name;
std::cout << "请输入鱼C身份证:";
std::cin >> OilData.uid;
std::cout << "请输入性别:";
std::cin >> OilData.sex;
std::cout << "录入成功, 请问需要保存吗?(Y/N)";
std::cin >> Save;
if( 'Y' == Save )
{
pOilData = &OilData;
if( WriteFishC( pOilData ) )
std::cout << "成功写入文件^_^\n";
else
std::cout << "写入文件失败T_T\n";
}
else
{
return;
}
std::cout << "/n请问需要再次录入吗?(Y/N)";
std::cin >> goon;
}
}
bool WriteFishC( FishOil *pOilData )
{
std::ofstream fileOutput("FishC.txt", std::ios::app);
// std::ios::app用来说明在老数据追加新数据
if( fileOutput.is_open() )
{
fileOutput << pOilData->name << " ";
fileOutput << pOilData->uid << " ";
fileOutput << pOilData->sex << "\n";
fileOutput.close();
std::cout << "数据成功保存到FishC.txt\n\n";
}
else
std::cout << "保存失败T_T\n";
} --------------------配置: mingw2.95 - CUI Debug, 编译器类型: MinGW (Old)--------------------
检查文件依赖性...
正在编译 C:\Users\Administrator\Desktop\FishOil\FishOil.cpp...
C:\Users\Administrator\Desktop\FishOil\FishOil.cpp:7: syntax error before `;'
C:\Users\Administrator\Desktop\FishOil\FishOil.cpp:8: syntax error before `;'
C:\Users\Administrator\Desktop\FishOil\FishOil.cpp:54: initialization to `char' from `const char *' lacks a cast
C:\Users\Administrator\Desktop\FishOil\FishOil.cpp:54: excess elements in aggregate initializer
C:\Users\Administrator\Desktop\FishOil\FishOil.cpp:62: `::string' undeclared (first use here)
C:\Users\Administrator\Desktop\FishOil\FishOil.cpp:62: parse error before `;'
C:\Users\Administrator\Desktop\FishOil\FishOil.cpp:80: `temp' undeclared (first use this function)
C:\Users\Administrator\Desktop\FishOil\FishOil.cpp:80: (Each undeclared identifier is reported only once
C:\Users\Administrator\Desktop\FishOil\FishOil.cpp:80: for each function it appears in.)
C:\Users\Administrator\Desktop\FishOil\FishOil.cpp:80: `::getline' undeclared (first use here)
C:\Users\Administrator\Desktop\FishOil\FishOil.cpp:103: `struct FishOil' has no member named `name'
C:\Users\Administrator\Desktop\FishOil\FishOil.cpp:105: `struct FishOil' has no member named `uid'
C:\Users\Administrator\Desktop\FishOil\FishOil.cpp:135: `struct FishOil' has no member named `name'
C:\Users\Administrator\Desktop\FishOil\FishOil.cpp:136: `struct FishOil' has no member named `uid'
构建中止 FishOil: 14 个错误, 0 个警告
这是为什么啊小白求解小甲鱼老师的原版课件啊 因为小甲鱼用的编译器支持c99标准,但是vc6.0不支持,所以可能有些函数会出错的,而且我看你用的头文件明好像是c++的头文件吧 A小小鸟 发表于 2018-7-12 17:08
因为小甲鱼用的编译器支持c99标准,但是vc6.0不支持,所以可能有些函数会出错的,而且我看你用的头文件明好 ...
我用C-Free 也不好使啊课件是刚刚花30鱼币下的啊我什么都没改过。。。。 xiaoxu5015 发表于 2018-7-12 17:10
我用C-Free 也不好使啊课件是刚刚花30鱼币下的啊我什么都没改过。。。。
头文件<iostream>是c++标准的头文件,如果是C语言的话,你可以将你的源文件的后缀名改成.cpp,这样来试试,就可以了 A小小鸟 发表于 2018-7-12 17:13
头文件是c++标准的头文件,如果是C语言的话,你可以将你的源文件的后缀名改成.cpp,这样来试试,就可以了
是.cpp文件 后缀 如果方便 麻烦你复制下 上面代码 用您的编译器 编译下 我真有点糊涂啦 万分感谢 xiaoxu5015 发表于 2018-7-12 17:15
是.cpp文件 后缀 如果方便 麻烦你复制下 上面代码 用您的编译器 编译下 我真有点糊涂啦 万分感谢
好,我用我的试试。你等一下 A小小鸟 发表于 2018-7-12 17:15
好,我用我的试试。你等一下
好的麻烦啦~! xiaoxu5015 发表于 2018-7-12 17:17
好的麻烦啦~!
我是可以的 A小小鸟 发表于 2018-7-12 17:23
我是可以的
我好纠结啊~!!!! 谢谢你兄弟~! xiaoxu5015 发表于 2018-7-12 17:24
我好纠结啊~!!!! 谢谢你兄弟~!
但是vc++6.0就出现错误了,我再查查错误原因是什么 xiaoxu5015 发表于 2018-7-12 17:24
我好纠结啊~!!!! 谢谢你兄弟~!
我找出原因了,因为c++对于string类型有一些错误,导致程序出错的,我把阳西的解决链接发给你,你自己改改https://blog.csdn.net/wen_yang/article/details/72631380
https://blog.csdn.net/xiaowu8858892520/article/details/70198623 A小小鸟 发表于 2018-7-12 17:33
我找出原因了,因为c++对于string类型有一些错误,导致程序出错的,我把阳西的解决链接发给你,你自己改 ...
#include <iostream>
#include <fstream>
#include <windows.h>
#include <string>
// 为了使用Sleep()函数
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 = {"小甲鱼", "fishc00001", 'M'};
FishOil OilInit;
OilInit.name="小甲鱼";
OilInit.uid="fishc00001";
OilInit.sex='M';
if( WriteFishC(&OilInit) == false )
std::cout << "初始化失败T_T\n";
return false;
}
bool ReadFishC()
{
std::string temp;
std::ifstream fileInput("FishC.txt");
if( fileInput.is_open() )
{
std::cout << "\n正在输出记录数据...... ";
for( int i=0; i <= 100; i++ ) // 打印百分比
{
std::cout.width(3);
std::cout << i << "%";
Sleep(50);
std::cout << "\b\b\b\b";
}
std::cout << "\n\n";
std::cout << " 姓名 " << "身份证" << " 性别 " << "\n\n";
while( std::getline( fileInput, temp ) )
{
std::cout << temp << " ";
std::cout << "\n";
}
std::cout << "\n\n";
return true;
}
else
return false;
}
void RecordFishC()
{
char goon, Save;
FishOil OilData;
FishOil *pOilData;
goon = 'Y';
while( 'Y' == goon )
{
std::cout << "请输入鱼C账号: ";
std::cin >> OilData.name;
std::cout << "请输入鱼C身份证:";
std::cin >> OilData.uid;
std::cout << "请输入性别:";
std::cin >> OilData.sex;
std::cout << "录入成功, 请问需要保存吗?(Y/N)";
std::cin >> Save;
if( 'Y' == Save )
{
pOilData = &OilData;
if( WriteFishC( pOilData ) )
std::cout << "成功写入文件^_^\n";
else
std::cout << "写入文件失败T_T\n";
}
else
{
return;
}
std::cout << "/n请问需要再次录入吗?(Y/N)";
std::cin >> goon;
}
}
bool WriteFishC( FishOil *pOilData )
{
std::ofstream fileOutput("FishC.txt", std::ios::app);
// std::ios::app用来说明在老数据追加新数据
if( fileOutput.is_open() )
{
fileOutput << pOilData->name << " ";
fileOutput << pOilData->uid << " ";
fileOutput << pOilData->sex << "\n";
fileOutput.close();
std::cout << "数据成功保存到FishC.txt\n\n";
}
else{
std::cout << "保存失败T_T\n";
}
return true;
}
A小小鸟 发表于 2018-7-12 17:33
我找出原因了,因为c++对于string类型有一些错误,导致程序出错的,我把阳西的解决链接发给你,你自己改 ...
我改了下现在能运行了还是好纠结啊为什么你的好使 我的不好使呢~!!!! A小小鸟 发表于 2018-7-12 17:33
我找出原因了,因为c++对于string类型有一些错误,导致程序出错的,我把阳西的解决链接发给你,你自己改 ...
感谢兄弟的支持 在下感激不尽 ~! 老弟,vc6是真.上古时代编译器了,用个code block或者devc++都比它顺手很多倍啊。 初代幻冰 发表于 2018-7-16 21:59
老弟,vc6是真.上古时代编译器了,用个code block或者devc++都比它顺手很多倍啊。
我是初学者在跟小甲鱼老师的 教程走呢教程里一直VC6我也就VC6啦~!!{:5_109:}
页:
[1]
2