编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第4章编程练习2
#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的更多相关文章
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习9
#include <iostream> #include <fstream> #include <cstdlib> #include <string> ...
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习8
#include <iostream> #include <fstream> #include <cstdlib> const int SIZE=20; using ...
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习7
#include <iostream> #include <string> #include <cctype> using namespace std; int m ...
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习6
#include <iostream> #include <string> using namespace std; const int MSIZE=100; struct j ...
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习5
#include <iostream> using namespace std; const double N1=35000; const int N2=15000; const int ...
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习4
#include <iostream> using namespace std; const int strsize=30; const int BOPSIZE=5; void showm ...
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习3
#include <iostream> using namespace std; void showmenu(void) { cout<<"Please enter ...
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习2
#include <iostream> #include <cctype> using namespace std; const int MAXSIZE=10; int mai ...
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习1
#include <iostream>#include <cctype>using namespace std;int main(){ char ch; while((ch=c ...
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第5章编程练习9
#include <iostream>using namespace std;int main(){ int num; cout<<"Enter number of ...
随机推荐
- python 在WINDOS虚拟环境部署
#查看电脑的版本 C:\Users\lys>pip -V pip 8.1.1 from e:\python\python3.5\lib\site-packages (python 3.5) #安 ...
- UPC 6616 Small Mulitple
D - Small Multiple 题目传送门 Time limit : 2sec / Memory limit : 256MB Score : 700 points Problem Stateme ...
- IIS中配置访问HTTPS
1,新建网站,选中类型为 https,然后更改SSL证书为你配置的SSL证书, 对于SSL证书的配置是这样的 点开第二步,然后点击 创建自签名证书 确定以后点开网站看到有个SSL, 双击进去,再选中 ...
- Swap file ".hive-site.xml.swp" already exists
1.使用命令[hadoop@slaver1 conf]$ ls -la查找出隐藏文件,然后删除报出来的错误文件. [hadoop@slaver1 conf]$ rm -rf .hive-site.xm ...
- 磁盘blk_update_request: I/O error
https://www.cnblogs.com/chris-cp/p/6340289.html
- es6 新增数据类型Symbol
es6在string number boolean null undefined object之外又新增了一种Symbol类型. Symbol意思是符号,有一个特性—每次创建一个Symbol值都是不一 ...
- mysql 一张表的多个字段关联另外一张表
SELECT vtiger_orderitem.orderid, ( SELECT vtiger_users.last_name FROM vtiger_users WHERE vtiger_orde ...
- Zabbix监控Low level discovery实时监控网站URL状态
今天我们来聊一聊Low level discovery这个功能,我们为什么要用到loe level discovery这个功能呢? 很多时候,在使用zabbix监控一些东西,需要对类似于Itens进行 ...
- Centos7X部署Zabbix监控
一:yum安装LAMP环境 zabbix-server端防火墙配置(可以选择iptables -F清空) iptables -A INPUT -m state --state NEW -m tcp - ...
- python编码,赋值和is的区别
1. == 与 is 的区别 赋值 == 比较值是否相等,is 比较,比较的是内存地址. 小数据池的作用是节省内存空间 数字的范围:-5 到 256 共用一个数据池 字符串范围:1.不能有特殊字符.2 ...