#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. OpenCV-Python入门教程4-颜色空间转换

    一.颜色空间转换 import cv2 import numpy as np img = cv2.imread('lena.jpg') # 转换成灰度图 img_gray = cv2.cvtColor ...

  2. 安装和配置bazel

    2018-12-26 21:56:23 编译和移植tensorflow的C/C++源码时,用到bazel这一构建工具.本篇blog记录遇到的安装.配置问题. 吐槽 构建工具,从make/ant/cma ...

  3. Windows10右键添加“在此处打开命令窗口”

    cmdHere.reg: Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\shell\OpenCmdHere] @= ...

  4. [转] Web前端开发工程师常用技术网站整理

    1.常用工具相关 有道云笔记 http://note.youdao.com/signIn/index.html 36镇-最好用的共享收藏夹 http://www.36zhen.com/ 浏览器同步测试 ...

  5. [转] 对express中next函数的一些理解

    最近公司在使用node做前后端分离,采用的web框架是express,所以对express框架进行了深入的了解,前段时间写了篇关于express路由的文章,但是在那篇文章中貌似少了一个很重要的内容,就 ...

  6. Java-把日期字符串转换成另一种格式的日期字符串

    package com.example.demo.utils; import java.text.ParseException; import java.text.SimpleDateFormat; ...

  7. element-ui上传文件带token

    template> <el-upload action="test" :headers="myHeaders"></el-upload& ...

  8. Nodejs通过账号密码连接MongoDB数据库

    转自https://blog.csdn.net/szu_lzz/article/details/77435804#commentBox 1.创建管理员 首先开启Mongo服务,然后切换admin数据库 ...

  9. Derive representation formula from Green’s identity

    This article introduces how to derive the representation formula used in BEM from Green's identity. ...

  10. vs code 前端如何以服务器模式打开 [安装服务器] server insteall

    首先要安装 vs code 和 node.js(既然是前端就必须回,不会的面壁思过)然后在命令符中输入 npm install -g live-server 进行安装,(简单的NPM安装)安装成功后在 ...