当需要读取一行字符串时,我们通常会有将这个字符串分开的想法
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
	string str;
	getline(cin, str);
	stringstream ssin(str);
	string s[10];
	int cnt = 0;
	while (ssin >> s[cnt]) cnt++;
	for (int i = 0; i < cnt; i++) 
		cout << s[i] << endl;
	return 0;
}
 
string的单个元素是char类型
 有的时候需要使用string头文件
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
	string str;
	getline(cin, str);
	stringstream ssin(str);
	int s[10] = { 0 };
	int cnt = 0;
	while (ssin >> s[cnt]) cnt++;
	for (int i = 0; i < cnt; i++) 
		cout << s[i] << endl;
	cout << s[1] + s[2] << endl;
	if (s[1] > 2) printf("数字\n");
	else puts("数字");
	return 0;
}
 

 这个是可以当成数字进行使用的(因为它可以进行自动类型推导)



















