我正在尝试从用户那里获得char
输入,然后根据键入的字符设置字符串。我做错了什么?
#include <iostream>
#include <string>
using namespace std;
int main()
{
char direction;
string printDirection;
cout << "Inbound or Outbound? (I or O)" << endl;
cin >> direction;
if (direction == 'o' || 'O'){
printDirection = "Outbound";
}
else if(direction == 'i' || 'I'){
printDirection = "Inbound";
}
else{
cout << "Error";
return 1;
}
printDirection;
return 0;
}
答案 0 :(得分:1)
if (direction == 'o' || 'O')
应该是
if (direction == 'o' || direction == 'O')
和其他if
语句中的相同内容。