以换行为准的
#include <string> string s; getline(cin, s);
讲stringstream的文章
http://www.cppblog.com/Sandywin/archive/2007/07/13/27984.html
#include <sstream> #include <string> string s; getline(cin, s);//输入字符串,获取到一行 stringstream ss(s);//初始化字符串流 string tmp; while (getline(ss, line, ' '))//按空格分割 { }
字符串转数据 可以利用函数
int stoi(const strings str, size_t* pos = 0, int base = 10) long stol(const strings str, size_t* pos = 0, int base = 10) float stof(const strings str, size_t* pos = 0) double stod(const strings str, size_t* pos = 0) int a=stoi(tmp,0,2);
还可以利用字符串流
string tmp; stringstream ss(s); int a; a<<ss;