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", ...
随机推荐
- eclipse启动Tomcat服务输入http://localhost:8080/报404解决方法
其实如果Tomcat能够正常启动,而就算输入http://localhost:8080时出现404错误,也不会影响Tomcat作为服务器运行.通过eclipse来启动tomcat会碰到“访问http: ...
- python----异常处理(二)
格式如下: try: pass except Exception as e:#如果上面出错,执行下面代码 pass else:#try如果没出错执行此下面代码 pass fin ...
- WCF基础:绑定(二)
在WCF的绑定体系中,经常会碰到ICommunicationObject接口,无论是IChannel接口还是IChannelListener/IChannelFactory接口都继承了ICommuni ...
- iOS7.1以后企业应用发布需要HTTPS协议,解决步骤
操作系统是Window下. 第一步安装软件 1.安装Tomcat6.0.35(Tomcat7.0.34测试通过) 2.安装JDK6(1.6.0_10-rc2,其它版本没测试) 3.安装openssl ...
- JavaScript例子
模态框(JavaScript) <!DOCTYPE html> <html lang="en"> <head> <meta charset ...
- 【后端】Python学习笔记
主要学习材料:<笨办法学习Python> ,(虫师的博客) 后面根据虫师的Python教程再对Pyhon进行了一次重新学习 ================================ ...
- vim编辑器安装命令使用命令和设置的使用总结
vim编辑器的安装 vi(vim)是上Linux非常常用的编辑器,很多Linux发行版都默认安装了vi(vim).vi(vim)命令繁多但是如果使用灵活之后将会大大提高效率.本文讲解主要是在Cento ...
- TCP/IP网络协议攻击
kali视频学习请看 http://www.cnblogs.com/lidong20179210/p/8909569.html 这部分涉及: ARP缓存欺骗攻击 ICMP重定向攻击 SYN FLOOD ...
- netcat 瑞士军刀
netcat被誉为网络安全界的‘瑞士军刀’,一个简单而有用的工具,透过使用TCP或UDP协议的网络连接去读写数据.它被设计成一个稳定的后门工具,能够直接由其它程序和脚本轻松驱动.同时,它也是一个功能强 ...
- IntelliJ IDEA 安装破解详解
https://github.com/tengj/IntelliJ-IDEA-Tutorial IntelliJ IDEA官方中文文档 https://blog.csdn.net/newabcc/ar ...