利用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变量。

最新文章

  1. mac 安装mvn 失败
  2. matlab clear
  3. poj 3070 矩阵快速幂模板
  4. iOS数组排序
  5. asp.net 小技巧
  6. webservice简单总结
  7. CSS中定位position
  8. linux去掉svn里记住的用户名密码
  9. spring jar包
  10. wpf动态增加删除控件
  11. 远程代理模式-Remote Proxy(Java实现)
  12. python panda::dataframe常用操作
  13. Educational Codeforces Round 53 (Rated for Div. 2)G. Yet Another LCP Problem
  14. Kotlin入门(28)Application单例化
  15. vue数据绑定数组,改变元素时不更新view问题
  16. 安装.src.rpm
  17. Atom选中多行操作
  18. jdbc驱动加载
  19. 函数和常用模块【day06】:logging模块(八)
  20. 【转】iPhone易被窃听应用三分钟即可获取所有信息

热门文章

  1. 菜鸟git学习
  2. python 补漏计划
  3. java-读取xml
  4. 【hrbust2293】棋盘村
  5. AndroidStudio 1.4配置NDK
  6. sqlmap --dns-domain模拟实践
  7. logistic regression与SVM
  8. [Android]学习笔记之布局
  9. 分享公司Entity与DTO之间数据拷贝的方法
  10. 百度地图JavaScript API [一]