gpt4 book ai didi

c++ - 我正在为祖母的生日开发C++程序,但是我一直收到错误代码:error C2451

转载 作者:行者123 更新时间:2023-12-03 07:11:58 24 4
gpt4 key购买 nike

我只参加了一个C++类(class),并计划用不同的东西填充我祖母的 child 的名字,而我目前所用的只是填充物。但是,当我尝试通过将字符串类型更改为整数来调试自己时,就像这样告诉我,然后我得到了新的错误代码。这是我目前拥有的程序,程序非常简单:

#include <iostream>
#include <string>
#include <cstring>

using namespace std;
string name;

string main() {
bool done = false;
while (!done) {

cout << "Enter one of your children's names, or press 'q' to quit" << endl;
cin >> name;

if (name = "q") {
done = true;
break;
}
else if (name = "Jason") {
cout << "Jason is your eldest son" << endl;
}
else if (name = "Aaron") {
cout << "Aaron was your second child" << endl;
}
else if (name = "Mandy") {
cout << "Mandy is your only girl" << endl;
}
else if (name = "Adam") {
cout << "Adam came after Mandy" << endl;
}
else if (name = "Ben") {
cout << "Ben is your youngest" << endl;
}
else {
cout << "That name does not exist for your children: try Jason, Aaron, Mandy, Adam, or Ben instead" << endl;
}
}
}

最佳答案

if and else if语句上,您需要更改==而不是=(赋值),以便检查两个操作数的值是否相等。
另外,我建议您在String main()中将其更改为:int main()

关于c++ - 我正在为祖母的生日开发C++程序,但是我一直收到错误代码:error C2451,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64690006/

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