编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第4章编程练习4

#include <iostream>
#include <string>
using namespace std;
int main()
{
 string fname;
 string lname;
 string name;
 cout<<"Enter your first name: ";
 getline(cin,fname);
 cout<<"Enter your last name: ";
 getline(cin,lname);
 name=lname+", "+fname;
 cout<<"Here's the information in a single string: "<<name<<endl;
 system("pause");
 return 0;
}

与使用char数组和头文件cstring中的函数比较,string对象和string中函数,操作简单,尤其对复杂的问题优势更加明显。

posted @ 2013-11-20 15:16  编程的爬行者  阅读(98)  评论(0编辑  收藏  举报