-1
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
string swapLastName(const string full_name, const string new_last_name)
{
string firstname;
string newname;
istringstream StrStream(full_name);
// seperate first name from full name
StrStream >> firstname;
// combines first name with new last name
newname=firstname +' '+ new_last_name;
// outputs new name
cout << "Your new name: " << newname << endl;
}
int main()
{
string full_name;
string new_last_name;
//input full name
cout << "Type your full name: ";
//getline to get entire full name
getline(cin, full_name);
//input new last name
cout << "Enter your new last name: ";
getline(cin, new_last_name);
swapLastName(full_name, new_last_name);
return 0;
}
新的C++的種類,需要一些幫助,爲什麼我不斷收到分割錯誤(核心轉儲)錯誤。一切工作,他們我想要它,但運行後,我得到分段錯誤(核心轉儲)C++分割錯誤(核心轉儲)錯誤
啓用您的編譯器警告。我很驚訝編譯器實際上可以用這個。 –
這不會編譯。是否適合你?你永遠不會從swapLastName返回一個字符串 – NickLamp
@NickLamp鏗鏘會顯然編譯這只是一個警告。那些混蛋。 –