第三题

题目需求:编写一个程序,它要求用户首先输入其名,再输入其姓。然后程序使用一个逗号和空格组合起来,并存储和显示组合结果。请使用string对象和头文件string 中的函数,下面是该程序运行的情况:

Enter your first name:Flip

Enter your last nae:Fleming

Here's the information in a single string:Fleming,Flip

本题知识点:

字符串输入输出

代码贴上:#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
int main()
{
    using namespace std;
    string Name1;
    string Name2;
    
    cout << "Enter your first name:\n";
    getline(cin,Name1);
    
    cout << "Enter your last name:\n";
    getline ( cin,Name2);
    
    cout << "Here's the information in a single string:" << Name2<<","<<" "<<Name1;
    return 0;
}

运行结果:

《c++primer plus》第6版第四章复合类型课后练习

 

 

 

 

 

 

 

 

r

如果有建议或错误,欢迎指出改正

相关文章:

  • 2022-12-23
  • 2021-10-09
  • 2021-09-20
  • 2021-12-04
  • 2021-11-24
  • 2022-02-06
  • 2021-12-25
  • 2021-06-02
猜你喜欢
  • 2022-03-09
  • 2021-04-03
  • 2021-06-13
  • 2022-12-23
  • 2022-01-16
  • 2021-07-12
相关资源
相似解决方案