编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第4章编程练习3
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char fname[20];
char lname[20];
char name[45];
cout<<"Enter your first name: ";
cin.getline(fname,20);
cout<<"Enter your last name: ";
cin.getline(lname,20);
strcpy(name,lname);
strcat(name,", ");
strcat(name,fname);
cout<<"Here's the information in a single string: "<<name<<endl;
system("pause");
return 0;
}
运行结果:
Enter your first name: Flip
Enter your last name: Fleming
Here's the information in a single string: Fleming, Flip