我已經做了兩個星期的C++了,我創建了一個非常簡單的程序,它允許用戶輸入他們的名字,然後輸出那裏的全名,這裏是代碼;C++ help - getline
#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;
不輸出空格任何幫助,將不勝感激! 謝謝。
嗯,你不告訴打印任何空格,爲什麼? – Mat
我該怎麼做? –
這就是你想要做的:'cout <<「你的全名是」<< first <<「」<< middle <<「<< << last << endl;' – Zane