回 帖 发 新 帖 刷新版面

主题:新手求助~!

#include <iostream>
#include <string>
using namespace std;


int main()
{
    string user_name;
    

    cout << "please enter your first name: ";
    cin >> user_name;

          cout <<"please enter your last name: ";
    cin >> user_name;
    
    cout << '\n'
         << "Hello,"
         << user_name
         << "... and goodbye!\n";
         return 0;

}


请问如何让这段代码中 输入的 first name 和 last name 同时一起输出

回复列表 (共1个回复)

沙发

#include <iostream>
#include <string>
using namespace std;


int main()
{
    char user_name1[30];
    char user_name2[30];
    

    cout << "please enter your first name: ";
    cin >> user_name1;

          cout <<"please enter your last name: ";
    cin >> user_name2;
    
    cout << '\n'
         << "Hello,"
         << strcat(user_name1,user_name2)
         << "... and goodbye!\n";
         return 0;
}
不知你会了没有,我也是初学者,只能这样了..

我来回复

您尚未登录,请登录后再回复。点此登录或注册