cin cout getline string
1.C++ code, When we want to read a number whatever the type is int or double , just use
cin >> Num_variable;
Then, after read number, if we want to read a line of words, we have to use
cin.ignore();
and next line
getline(cin, String);
after we read a Num_variable, a '\n' char is still saved in the input buffer, the "cin.ignore()" can clear the input buffer
so, the String can be set to really what you want to read, otherwise if we don't use cin.ignore(), code will read blank line("blank\n") to String.
e.g.,
cin >> NUM;
cin.ignore();
getline(cin, String0);
getline(cin, String1);
getline(cin, String2);
·······
2. C++ code, When we want to print a double type of number, we have to set the precision of this number.
we have to #include <iomanip>
before cout, we can use
cout << setiosflags(ios::fixed);
and next line
cout << setprecision(1) << e << endl;
code will print 1 number after the number_point.
cin cout getline string的更多相关文章
- C++语言中cin cin.getline cin.get getline gets getchar 的用法实例
#include <iostream> #include <string> using namespace std; //关于cin cin.getline cin.get g ...
- cin 和 getline 混用中需要注意的问题
这段时间在刷题过程中遇到一个cin和getline混合使用中的问题,解决之后记录如下: 先来看一段代码 #include <iostream> #include <string> ...
- 洛谷P1765 手机_NOI导刊2010普及(10) 关于cin和getline的一些区别 以及一些STL
一. cin>>s:cin>>是由两部分构成的,cin和>>,其中cin是输入流istream类的一个对象,隶属于iostream函数库而>>则是运算符 ...
- acdream B - 郭式树 (水题 卡cin,cout, 卡LL)
题目 输入正好是long long的最大, 但是答案超long long 所以用unsigned, 不能用cin cout否则一定超时: 不能用abs(), abs 只用于整数. unsigned ...
- printf scanf cin cout的区别与特征
printf和scanf是c语言的输入输出,学习c++以后,自然是用cin cout这两个更简单的输入输出 printf scanf 都需要进行格式控制,比较麻烦,但优点是速度比较快,毕竟多做了一些事 ...
- C++输入输出流 cin/cout 及格式化输出简介
C++ 可通过流的概念进行程序与外界环境( 用户.文件等 )之间的交互.流是一种将数据自源( source )推送至目的地( destination )的管道.在 C++ 中,与标准输入/输出相关的流 ...
- 892B. Wrath#愤怒的连环杀人事件(cin/cout的加速)
题目出处:http://codeforces.com/problemset/problem/892/B 题目大意:一队人同时举刀捅死前面一些人后还活着几个 #include<iostream&g ...
- 在c++中,标准输入string时cin 与getline两个函数之间的区别
cin: cin函数是标准库的输入函数,在读取string时遵循以下规则: 1)读取并忽略开头所有的空白符(包括空格.换行符.制表符). 2)读取字符直到遇到空白符,读取终止. 例如: 当输入的是“ ...
- scanf printf gets() puts(),cin cout
最近在练机试题,常用的C和C++输入输出如下: 1 scanf 和printf int a; scanf("%d",&a) ; printf("%d", ...
随机推荐
- 前端画图之iphoneSE主屏
今天逛园子,无意间看到一个用div+css画的Macbook Air的博客,瞬间想到很久之前我也做过类似的事, 而且,当时写完之后,真的是成就感爆棚啊!我去开源中国上翻到了我当时贴的源码,当时是在手机 ...
- 《Drools7.0.0.Final规则引擎教程》第4章 4.2 lock-on-active
lock-on-active 当在规则上使用ruleflow-group属性或agenda-group属性的时候,将lock-on-active 属性的值设置为true,可避免因某些Fact对象被修改 ...
- mac root
我在mac下,用su登录root用户 但是提醒 su:Sorry 然后按照网上的方法弄了好多次,都没成功,说是要修改/etc/group 文件中,wheel后添加自己的用户名,用逗号分隔多个用户, ...
- HSRP/VRRP/GLBP
当网络足够大的时候,网络规划师要考虑的技光是网络本身的性能问题,冗余技术也是必不可少的. 常见的冗余网关技术有• 热备份路由协议(HSRP).• 虚拟路由器冗余协议(VRRP)• 网关负载均衡协议(G ...
- Python虚拟环境设置
Python2环境 首先,我们用pip安装virtualenv: pip3 install virtualenv 然后,假定我们要开发一个新的项目,需要一套独立的Python运行环境,可以这么做: 第 ...
- ORM版,学生管理系统02
学生管理系统 urls.py url(r'^student_list/$',views.student_list,name="student_list"), url(r'^dele ...
- (八)java运算符
算数运算符 + - * / % ++ -- class Ysf { public static void main(String[] args) { System.out.println(5/2);/ ...
- LeetCode Split Concatenated Strings
原题链接在这里:https://leetcode.com/problems/split-concatenated-strings/description/ 题目: Given a list of st ...
- latch的产生和消除
一直都知道fpga中有latch这么一回事,但是一直都不太清楚到底什么是锁存器,它是怎么产生的,它到底和寄存器有多少区别,它怎么消除.为什么说他不好? 一,是什么 锁存器是一种在异步时序电路系统中,对 ...
- 阿里云ESC上面部署项目
注意:我这里的服务器是Windows系统,后面会研究Linux下的命令 1.将javaWEB项目打包为war包 右击项目,先择“Export ” 2.通过“附件”->“远程连接桌面”,连接到服务 ...