我已经做 C++ 两个星期了,我正在创建一个非常简单的程序,它允许用户输入他们的名字,然后输出全名,这是代码;
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string first ;
string middle ;
string last;
cout << "What is your firstname?" << endl;
getline(cin, first);
cout << "Your firstname is ";
first = first;
cout << first << endl;
cout << endl;
cout << "What is your middle name?" << endl;
getline(cin, middle);
cout << "Your middle name is ";
middle = middle;
cout << middle << endl;
cout << endl;
cout << "What is your lastname?" << endl;
getline(cin, last);
cout << "Your lastname is ";
last = last;
cout << last << endl;
cout << endl;
cout << "Your full name is " << first + middle + last << endl;
system ("pause");
return 0;
}
我遇到的问题是它不会在最后一个 cout 中输出空格
cout << "Your full name is " << first + middle + last << endl;
任何帮助,将不胜感激!谢谢。