#include <iostream>
#include <string>
int main()
{
 using namespace std;
 string name;
 string dessert;
 
 cout<<"Enter your name:\n";
 getline(cin,name);//存在问题,输入两次Enter键,才会运行后面一句cout语句,待解决
 cout<<"Enter your favorite dessert:\n";
 getline(cin,dessert);
 cout<<"I have some delicious "<<dessert;
 cout<<" for you, "<<name<<".\n";
 system("pause");
 return 0;
}

运行结果:

Enter your name:

Han Meimei<Enter>

<Enter>

Enter your favorite dessert:

Radish Torte<Enter>

<Enter>

I have some delicious Radish Torte for you, Han Meimei.

对于存在的getline需要输入两次Enter键才能输出后面一句的问题,解决办法:

修改string头文件,

找到 else if(_Tr::eq((_E)_C,_D))

{_Chg=true;

//_I.rdbuf()->snextc();/* 注释掉这句,修改为下一句*/

_I.rdbuf()->sbumpc();

break;}

这样原本的问题就解决了。

修改后运行结果为:

Enter your name:

Han Meimei<Enter>

Enter your favorite dessert:

Radish Torte<Enter>

I have some delicious Radish Torte for you, Han Meimei.

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

  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. 激活函数的比较,sigmoid,tanh,relu

    1. 什么是激活函数 如下图,在神经元中,输入inputs通过加权.求和后,还被作用了一个函数.这个函数就是激活函数Activation Function 2. 为什么要用激活函数 如果不用激活函数, ...

  2. RabbitMq相关运维

    # 命令查询所有用户列表rabbitmqctl list_users # 使用命令对 xiandian-admin 用户进行授权set_permissions xiandian-admin '.*' ...

  3. 查看python脚本的运行pid,让python脚本后台运行

    ps -ef | grep Productor.py | grep -v grep # 先测试好 python3  /usr/local/software/ELK/Productor.py # 没问题 ...

  4. dubbo的工作原理

    dubbo工作原理 第一层:service层,接口层,给服务提供者和消费者来实现的 第二层:config层,配置层,主要是对dubbo进行各种配置的 第三层:proxy层,服务代理层,透明生成客户端的 ...

  5. plsql的汉化问题

    1:汉化工具下载地址:https://www.allroundautomations.com/bodyplsqldevreg.html 汉化吗.然后选择chinese就行了: 2:对安装(解压缩好的哦 ...

  6. Context连接和断开的情况下的CRUD操作

    连续情况下的CRUD操作是一项相当容易的任务,因为默认情况下,上下文会自动跟踪实体在其生命周期中发生的更改,AutoDetectChangesEnabled为true. 以下示例显示如何添加,更新和删 ...

  7. Java集合源码学习(一)Collection概览

    1.集合框架 Java集合框架包含了大部分Java开发中用到的数据结构,主要包括List列表.Set集合.Map映射.迭代器(Iterator.Enumeration).工具类(Arrays.Coll ...

  8. 用Web api /Nancy 通过Owin Self Host简易实现一个 Http 服务器

    过去做 端游的Http 服务器 用的WebApi 或者Mvc架构,都是放在iis...而我已经是懒出一个地步,并不想去配iis,或者去管理iis,所以我很喜欢 Self host 的启动方式. C#做 ...

  9. Azure附加新磁盘,差点掉进去的那个坑,注意临时数据盘

    接今早的mysql问题,最终原因是mysql数据库的数据库文件以及pid丢失,当我还纳闷为什么丢失的情况下 我研究了下Azure云平台的数据磁盘原理,在Azure下,新建vm(centos)后只会提供 ...

  10. Python连接mysql出错,_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")