#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. 51Nod 1265 四点共面(计算几何)

    1265 四点共面  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出三维空间上的四个点(点与点的位置均不相同),判断这4个点是否在同一个平面内(4点共线也算共面). ...

  2. 虚拟机下安装Centos7并配置Apache+PHP+Mysql+phpmyadmin+wordpress

    一.安装Apache yum install httpd 安装成功后,Apache操作命令: systemctl start httpd //启动apache systemctl stop httpd ...

  3. DDD工作流持久化(十六)

    找到对应的sql文件执行sql语句 产生如下的表: 添加引用: 添加命名空间: using System.Activities.DurableInstancing; using System.Runt ...

  4. EntityFramework Reverse POCO Code First 反向生成器

    https://marketplace.visualstudio.com/items?itemName=SimonHughes.EntityFrameworkReversePOCOGenerator ...

  5. 原生开发小程序 和 wepy 、 mpvue, Taro 对比

    https://blog.csdn.net/yang450712123/article/details/79623518 mpvue https://www.cnblogs.com/bgwhite/p ...

  6. Git reset与checkout的区别

    reset: 将暂存区的文件回撤到工作区,文件内容不会有任何变化 checkout: 将工作区文件恢复到上一次commit时的内容,将会丢失修改了但未加入暂存区的内容

  7. Summary of continuous function spaces

    In general differential calculus, we have learned the definitions of function continuity, such as fu ...

  8. Kafka/Zookeeper集群的实现(二)

    [root@kafkazk1 ~]# wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.12/zookeeper-3.4.12. ...

  9. Python 实现红绿灯

    一.通过Event来实现两个或多个线程间的交互,下面是一个红绿灯的例子,即起动一个线程做交通指挥信号灯,一个线程做车辆,车辆行驶按红灯停,绿灯行的规则. #!/usr/bin/python # -*- ...

  10. 关于ubuntu的ssh远程登录的问题

    一. 安装ssh(参考:http://liuyifan789.iteye.com/blog/2068263) sudo apt-get install openssh-server openssh-c ...