C++ c++;visual studio错误,我感到困惑
我一直收到一个错误:意外的文件结尾被发现,我完全迷路了。我已经检查了咖喱大括号和圆括号,我在课后放了一个分号,我想不出有什么问题。非常感谢C++ c++;visual studio错误,我感到困惑,c++,visual-studio-2010,C++,Visual Studio 2010,我一直收到一个错误:意外的文件结尾被发现,我完全迷路了。我已经检查了咖喱大括号和圆括号,我在课后放了一个分号,我想不出有什么问题。非常感谢 #include<iostream> #include<fstream> #include<string> using namespace std; class operations{ void checkout(){ cout << "Check out here!!";
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class operations{
void checkout(){
cout << "Check out here!!";
}
}
void main(){
string item;
int choice;
cout << "What do you want to do? " << endl;
cout << "Press 1 for checking out " << endl;
cout << "Press 2 for stocking " << endl;
cout << "Press 3 looking at recipts " << endl;
cin >> choice;
cout << choice;
if(choice == 1){
void checkout();
}
/*ofstream myfile;
myfile.open("inventory.txt");
if(myfile.is_open()){
cout << "Enter a grocery item" << endl;
getline(cin,item);
myfile << item;
}
cout << "Your grocery item is " << item;
myfile.close();
system("pause");*/
};
#包括
#包括
#包括
使用名称空间std;
班级作业{
无效签出(){
库特
类定义需要一个尾随分号,而不是主函数
class operations{
void checkout(){
cout << "Check out here!!";
}
};
类操作{
无效签出(){
cout我认为您应该将此添加到文件的顶部(使其成为第一行):
这是您的代码,在我解释您想要执行的操作时进行了更正
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class operations
{
public:void checkout()
{
cout << "Check out here!!";
}
};
int main()
{
string item;
int choice;
operations op;
cout << "What do you want to do? " << endl;
cout << "Press 1 for checking out " << endl;
cout << "Press 2 for stocking " << endl;
cout << "Press 3 looking at recipts " << endl;
cin >> choice;
cout << choice;
if(choice == 1)
{
op.checkout();
}
return 0;
}
这样你就可以简单地用
checkout()
将分号放在main()
函数的末尾,而不是类声明的末尾。此外,在main()
中调用void checkout();
在语法上是无效的。首先,因为您不编写返回类型(void
)当你调用一个函数时,第二,因为checkout()
是一个成员函数,而不是一个独立的函数,所以你必须在一个对象上调用它,该对象是操作类的一个实例。我仍然得到了错误。它在第39行显示,但我的程序只有38行,而你是对的,main
应该返回int',VC++接受
void main`@BigBoss,但它是正确的在托管环境中具有技术上未定义的行为。不需要添加返回0;
。没有任何迹象表明预编译头与此有关。
void checkout()
{
cout << "Check out here!!";
}
checkout()