所以,我已经搜索周围的答案,并且多人得到了相同的错误响应,但我看不出他们的错误如何修复我的代码。error:expected unqualified-id
我开始尝试C++昨天,但我经历了大多的Python也是C#
我想提出一个简单的通讯录,只是为了学习。 我没有完成类或任何其他实现,只需要这个固定的第一。
确切的错误是
而且代码是在这里
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
bool running = true;
public class Contact
{
private:
string firstname = "";
string lastname = "";
string phonenumber = "";
public:
Contact()
{
this.firstname = "Alfred";
}
};
int main()
{
cout << "Welcome to the Contact book!" << endl <<
"Made by X";
while (running)
{
cout << "1. Add contact" << endl
<< "2. List contacts" << endl
<< "3. Quit" << endl;
cout << "Choice: ";
string mystr;
getline(cin, mystr);
int choice;
stringstream(mystr) >> choice;
switch (choice)
{
case 1: cout << "asd";
case 2: cout << "asd2";
case 3: running = false;
default : cout << "Invalid integer";
}
}
return 0;
}
提前感谢!
这是C++,而不是C#。 – 2013-03-15 16:41:21
这就是我把它标记为和描述中写的,对不起,如果我不够清楚 – 2013-03-15 16:42:31
不,你没有错误地使用正确的标签(据我所知),我的意思是说,公共类'类似于C#代码。 – 2013-03-15 16:45:27