gpt4 book ai didi

c++ - 错误 : expected unqualified-id

转载 作者:太空狗 更新时间:2023-10-29 23:36:30 25 4
gpt4 key购买 nike

<分区>

所以,我四处寻找答案,很多人得到了相同的错误响应,但我看不出他们的错误如何修复我的代码。

我昨天开始尝试 C++,但我对 Python 和 C# 都有经验

我正在制作一个简单的通讯录,仅供学习。我还没有完成类或任何其他实现,只需要先解决这个问题。

准确的错误是

kontaktbok.cpp:9: error: expected unqualified-id before 'public'

代码在这里

#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;
}

提前致谢!

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com