#include <iostream>
#include <string>
int main(void)
{
using std::cout;
using std::cin;
using std::string;
string name;
int n1, n2;
cout << "What is your name ?\n";
cin >> name;
cout << "Hello " << name.c_str() <<"!\n"
<< "Please give me two number separated by space\n";
cin >> n1 >> n2;
cout << "Sum of " << n1 << " + " << n2 << " is " << n1 + n2 << "\n";
return 0;
}
我的控制台输入/输出看起来是这样的:什么是导致有关字符串的这个错误?
你叫什么名字?
John Titor
Hello John!
请给我两个数字之间用空格分隔
0 + 1961462997总和为1961462997
它不打印的全名,只有“约翰”,它甚至不问我puting 2数字。
使用'函数getline()'函数来获取全情投入。 'std :: cin'逐字读取字符串。 –