我是不熟悉C ++编码的人。当我遇到问题时,我正在学习如何获取用户输入。这是代码:
#include <iostream>
using namespace std;
int main() {
string YourName;
cout << "Hi there!!!" << endl;
cout << "Please enter your name: ";//prompting the user to input his/her name
cin >> YourName;//getting the user input into the variable
cout << "Hi " << YourName;//printing an appropriate response
//a simple calculator
int Num1, Num2;
cout << "\nEnter a number: ";
cin >> Num1;
cout << "Enter the second number: ";
cin >> Num2;
int sum = Num1 + Num2;
cout << Num1 << "+" << Num2 << "=" << sum;
return 0;
}
当我对变量Yourname使用单个单词时,效果很好。但是,当我使用全名大写时,例如约翰·麦克洛伊(John Mcloy),我得到一个奇怪的结果……。
希望我的问题很清楚...