C++ 试图获取用户输入并发送一条消息,当我输入一个有效的名称时,它会发送所有的信息 #包括 #包括 #包括 使用名称空间std; int main(){ 弦枪=”; 如果条件不能以这种方式工作,则不能
。 如果你想要这个,你必须这样写:C++ 试图获取用户输入并发送一条消息,当我输入一个有效的名称时,它会发送所有的信息 #包括 #包括 #包括 使用名称空间std; int main(){ 弦枪=”; 如果条件不能以这种方式工作,则不能,c++,stringstream,C++,Stringstream,。 如果你想要这个,你必须这样写: #include <iostream> #include <string> #include <sstream> using namespace std; int main() { string gun = ""; cout << "Enter The Gun You Would Like To Know The Type Of Ammo For: \n"; getline(cin,
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main() {
string gun = "";
cout << "Enter The Gun You Would Like To Know The Type Of Ammo For: \n";
getline(cin, gun);
if (gun == "b95" || "B95" || "windchester" || "wind chester" || "Windchester" || "Wind Chester" || "longhorn" || "Long Horn" || "fal" || "FAL")
{
cout << "The Type Of Ammo For The " << gun << " Is 308 Windchester";
}
if (gun == "izh rifle" || "IZH Rifle" || "izhrifle" || "izh rifle" || "sks" || "SKS" || "akm" || "AKM")
{
cout << "The Type Of Ammo For The " << gun << " 7.62x39mm";
}
if (gun == "Mangnum" || "mangnum" || "Repetor" || "repetor")
{
cout << "The Type Of Ammo For The " << gun << ".357";
}
return 0;
}
基本上比较需要两个值进行比较,而不是一个值。
< P>不能在C++中写这样的布尔表达式。布尔表达式的每一个都是布尔值,所以在你的情况下,所有三个都是真的,因为在布尔表达式中非空字符串是真的。 请阅读有关布尔表达式的内容并编写类似的内容如果(输入=“STR1”,输入=“STR2”等)如果你的条件不做你想让他们做的事,请从C++中学习C++,而不是猜测。
if (gun == "izh rifle" || gun == "IZH Rifle" || gun == "izhrifle" || gun == "izh rifle" ||
gun == "sks" ||gun == "SKS" ||gun == "akm" ||gun == "AKM")