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", ...
随机推荐
- saltstack笔记
Saltstack类似于puppet salt的核心功能使用命令 发送到远程系统是并行的而不是串行的使用安全加密的协议使用最小最快的网络载荷提供简单的编程接口 Python编写,相当轻量级通讯层采用z ...
- angular js jquery中post请求的一点小区别
这也是最近遇到的坑,还是之前那个项目,现在要实现登录功能. 背景:注册功能之前已经跑通了.前端用的是jquery后台是springMVC.鉴于注册和登录有些接口功能是类似的(比如注册确保邮箱是没有注册 ...
- 【2018年全国多校算法寒假训练营练习比赛(第五场)-E】情人节的电灯泡(二维树状数组单点更新+区间查询)
试题链接:https://www.nowcoder.com/acm/contest/77/E 题目描述 情人节到了,小芳和小明手牵手,打算过一个完美的情人节,但是小刚偏偏也来了,当了一个明晃晃的电灯泡 ...
- Apk大瘦身
Android的apk文件越来越大了这已经是一个不争的事实.在Android 还是最初版本的时候,一个app的apk文件大小也还只有2 MB左右,到了现在,一个app的apk文件大小已经升级到10MB ...
- react: menuService
1.获取菜单对象 static findCurrentItem(items, currentState, currentItem) { _.forEach(items, function (item) ...
- Thrift之java实例
一.java实例 1.下载与安装thrift工具 http://thrift.apache.org/download/ .服务器代码 服务Test实现类 package com.zychen.thri ...
- opencv roi resize 会导致内存拷贝产生子图像
opencv roi区域 resize之后,roi的引用已不是原图的引用,而是内存拷贝产生的子图像. http://blog.csdn.net/qianqing13579/article/detail ...
- Python判断unicode是汉字,数字,英文,或者其他字符
功能: 判断unicode是否是汉字,数字,英文,或者是否是(汉字,数字和英文字符之外的)其他字符. 全角.半角符号相互转换. 全角.半角? 全角--指一个字符占用两个标准字符位置. 汉字字符和规定了 ...
- HelloWorld 模块
helloworld.c 代码 #include <linux/init.h> #include <linux/module.h> MODULE_LICENSE("D ...
- Python基本特殊方法之__format__
__format__()方法 __format__()传参方法:someobject.__format__(specification) specification为指定格式,当应用程序中出现&quo ...