c/c++ 缓冲区的刷新
2024-10-16 06:28:47
利用string 对象查看缓冲区的变化,因为每个string对象在输入时会以空格作为分界。
#include<iostream> #include<string> using namespace std; int main() { string s1; string s2; string s3; cout<< "this is a while circle, and it's different with getline():"<<endl; string word; while( cin>>word ) { cout<<word<<endl; if( word == "exit" ) break; } cout<<"first try; input a char, then output; three times:"<<endl; cin>>s1; cout<<s1<<endl; cin>>s2; cout<<s2<<endl; cin>>s3; cout<<s3<<endl; cout<<"second try; input three char once, then output:"<<endl; cin>>s1>>s2>>s3; cout<<s1<<endl; cout<<"s2:"<<s2<<endl; cout<<"s3:"<<s3<<endl; cout<<"s1:"<<s1<<endl; return 0; }
在循环时,如果输入的是用空格隔开的几个string值,那么将依次输出这几个值。
而在非循环时,会将空格隔开的几个值依次赋值给要求输入的string变量。
最新文章
- mac 安装mvn 失败
- matlab clear
- poj 3070 矩阵快速幂模板
- iOS数组排序
- asp.net 小技巧
- webservice简单总结
- CSS中定位position
- linux去掉svn里记住的用户名密码
- spring jar包
- wpf动态增加删除控件
- 远程代理模式-Remote Proxy(Java实现)
- python panda::dataframe常用操作
- Educational Codeforces Round 53 (Rated for Div. 2)G. Yet Another LCP Problem
- Kotlin入门(28)Application单例化
- vue数据绑定数组,改变元素时不更新view问题
- 安装.src.rpm
- Atom选中多行操作
- jdbc驱动加载
- 函数和常用模块【day06】:logging模块(八)
- 【转】iPhone易被窃听应用三分钟即可获取所有信息