编程菜鸟的日记-初学尝试编程-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 ...
随机推荐
- VUE失去焦点提交修改值
xxx.vue <input class="ml6 w85 bdr-6 bd-none text-center" type="text" v-model= ...
- 静态属性property
静态属性property(是通过对象去使用) property是一种特殊的属性,访问它时会执行一段功能(函数)然后返回值 1 . 通过@property修饰过的函数属性,调用的时候无需在加() cla ...
- 20165323 结对编程之四则运算week2-整体总结
一.需求 实现一个命令行程序,要求: 1.自动生成小学四则运算题目(加.减.乘.除) 2.支持整数 3.支持多运算符(比如生成包含100个运算符的题目) 4.支持真分数 5.能判断错误,在输入错误结果 ...
- 记录mysql正在执行的SQL语句
show variables like "general_log%"; SET GLOBAL general_log = 'ON';SET GLOBAL general_log = ...
- js模板引擎art-Template(以前的artTemplate)
使用js.jquery动态生成html会非常麻烦.现在的模板引擎可以很简单的解决这个问题.比如腾讯出的art-Template 官网:http://aui.github.io/art-template ...
- 使用Github Pages和Hexo构建个人博客
Github Pages可以创建免费的静态站点,支持自带主题.支持自制页面等,并且可以使用Jekyll或者Hexo等静态博客框架进行管理. 独立博客是博客园等博客平台之外的一个良好补充,相比使用虚拟主 ...
- UIImageView的常用方法
//初始化 init(image: UIImage!) @availability(iOS, introduced=3.0)//初始化,highlightedImage 高亮图片 init(image ...
- HTML5漫谈(7)——如何保护HTML5应用代码
独家供稿:移动Labs HTML5应用采用的仍然是Javascript(JS).HTML.CSS 等Web语言,因而其代码保护就是这些Web代码的保护,而HTML5应用主要功能一般采用JS实现,因此J ...
- python编码,赋值和is的区别
1. == 与 is 的区别 赋值 == 比较值是否相等,is 比较,比较的是内存地址. 小数据池的作用是节省内存空间 数字的范围:-5 到 256 共用一个数据池 字符串范围:1.不能有特殊字符.2 ...
- 不利用C语言库函数,实现字符串相关函数
#include<stdio.h> int strLength(char* s)//求字符长度 { ; while(s[i]!=NULL) { i++; } return i; } int ...