#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中函数,操作简单,尤其对复杂的问题优势更加明显。

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

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

    #include <iostream> #include <fstream> #include <cstdlib> #include <string> ...

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

    #include <iostream> #include <fstream> #include <cstdlib> const int SIZE=20; using ...

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

    #include <iostream> #include <string> #include <cctype> using namespace std; int m ...

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

    #include <iostream> #include <string> using namespace std; const int MSIZE=100; struct j ...

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

    #include <iostream> using namespace std; const double N1=35000; const int N2=15000; const int ...

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

    #include <iostream> using namespace std; const int strsize=30; const int BOPSIZE=5; void showm ...

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

    #include <iostream> using namespace std; void showmenu(void) { cout<<"Please enter ...

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

    #include <iostream> #include <cctype> using namespace std; const int MAXSIZE=10; int mai ...

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

    #include <iostream>#include <cctype>using namespace std;int main(){ char ch; while((ch=c ...

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

    #include <iostream>using namespace std;int main(){ int num; cout<<"Enter number of ...

随机推荐

  1. 'tensorflow' has no attribute 'sub'

    在学习tensorflow的时候,照到官方的例子做,发现了一个 Traceback (most recent call last): File , in <module> sub = tf ...

  2. Zabbix监控Low level discovery实时监控网站URL状态

    今天我们来聊一聊Low level discovery这个功能,我们为什么要用到loe level discovery这个功能呢? 很多时候,在使用zabbix监控一些东西,需要对类似于Itens进行 ...

  3. Java中用Scanner扫描控制台输入时的一个小问题

    package com.hxl; import java.util.Scanner; public class Test { public static void main(String[] args ...

  4. Hive| DDL| DML

    类型转换 可以使用CAST操作显示进行数据类型转换 例如CAST(' 转换成整数1:如果强制类型转换失败,如执行CAST('X' AS INT),表达式返回空值 NULL. : jdbc:hive2: ...

  5. 队列queue的一些操作

    1. q = queue.Queue(5) 实例化,5为队列长度 2. q.put("haha") 将数据加入队列,计数器+1 3. q.get() 取出数据,计数器不变 4. q ...

  6. javascript记忆

    Math.round()和ToFixed() Math.round(1.6)=2 Math.round(-1.4)=-1 var k = 1.74.toFixed(1), m = 1.75.toFix ...

  7. dubbo spring bean id冲突

    service-security-provider应用有provider和consumer配置文件 其中secutrity-consumer引用两个服务 <dubbo:reference int ...

  8. Scala-Unit5-Scala面对对象与模式匹配

    Java中的面向对象:万物皆对象. 我们要封装数据,定义模板等操作,素以我们需要面向对象. ====================================================== ...

  9. 发布xxl-job executor dotnet core 执行器的实现

    DotXxlJob [github][https://github.com/xuanye/DotXxlJob] xxl-job的dotnet core 执行器实现,支持XXL-JOB 2.0+ 1 X ...

  10. IDEA快速入门(Mac版)

    [持续更新]一篇今年年头的老文章顺道发布了,大家有任何问题可以留言沟通.当时刚刚加入团团,愿大家有机会还是购买一台MAC,确实能给大家的效率赋能,虽然在一开始会有一些艰难!⛽️ 望借着换工作的东风,好 ...