我目前在课堂上使用Putty虚拟机(UNIX),并且正在做简短的C ++作业。任务是:“创建一个C ++程序,该程序进行测试以查看文件帐户是否存在并打印一条消息以说明文件是否存在”
这就是我所拥有的,但是当我尝试编译代码时,出现此错误:error:':: main'必须返回'int'
#include<iostream>
#include<fstream>
using namespace std;
inline bool exists_test1 (const std::string& name) {
if (FILE *file = fopen(name.c_str(), "r")) {
fclose(file);
return true;
} else {
return false;
}
}
void main()
{
string s;
cout<<"Enter filename";
cin>>s;
bool ans =exists_test1(s);
if(ans)
{
cout<<"File Exist"<<endl;
}
else
{
cout<<"File Does not Exist";
}
}
Run Code Online (Sandbox Code Playgroud)