#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. [转]fiddler 抓包 HTTPS 请求

    教程开始 安装 fiddler 首先准备一台可以上网的 windos 电脑,准备一部智能手机. fiddler 抓包工具:下载地址( 自行百度一搜一大片).安装,打开如果遇到. net framewo ...

  2. [转]Maven与nexus关系

    开始在使用Maven时,总是会听到nexus这个词,一会儿maven,一会儿nexus,当时很是困惑,nexus是什么呢,为什么它总是和maven一起被提到呢? 我们一步一步来了解吧. 一.了解Mav ...

  3. bash: cannot create temp file for here-document: Read-only file system

    文件系统被强制只读问题,第一眼看到百度了一下,说可能磁盘坏了.卧槽我都吓懵了系统盘坏了,闹着玩呢,然后接着查资料,排查 mount 查看所有挂载,发现根目录的挂载权限是ro只读. /dev/sda2 ...

  4. Python学习(五) —— 文件操作

    一.文件操作 1.文件操作:数据持久化的一种      步骤:找到文件,打开文件,操作:读.写.追写,关闭文件      打开文件:f = open(文件路径,操作模式,编码方式),f:文件句柄.文件 ...

  5. BZOJ1823 [JSOI2010]满汉全席 2-sat

    原文链接http://www.cnblogs.com/zhouzhendong/p/8125944.html 题目传送门 - BZOJ1823 题意概括 有n道菜,分别可以做成满式和汉式(每道菜只能做 ...

  6. Hive| 查询

    Hive中执行SQL语句时,出现类似于“Display all 469 possibilities? (y or n)”的错误,根本原因是因为SQL语句中存在tab键导致,tab键在linux系统中是 ...

  7. 044 hive与mysql两种数据源之间的join

    这篇文章是基于上一篇文章的续集 一:需求 1.图形表示 二:程序 1.程序. package com.scala.it import java.util.Properties import org.a ...

  8. Linux下的Sreen命令使用

    详细的介绍请参看:http://www.cnblogs.com/mchina/archive/2013/01/30/2880680.html 一.简介 GNU Screen是一款由GNU计划开发的用于 ...

  9. Java常用API——时间类

    前言:Java.util.*工具包中,包含了集合框架,旧集合类,事件模型,日期和时间设施,国际化和其他使用程序类 (字符串.随机数生成器和位数组) 一.日期类Date 1.概述 Date是一个薄包装类 ...

  10. POJ 2488 A Knight's Journey-dfs

    题目链接:http://poj.org/problem?id=2488 题目解读:首先得弄清楚国际象棋中关于“马走日”的规则,如上图中的马,它的下一步的走法有8中,所以对每一个位置的马,它所能走的8个 ...