a********e 发帖数: 508 | 1 单词和数字是用space分隔的
getline(cin,str,' ')倒是一次可以读入一个,但是只能存储为string类型
。而且但是我不知道怎么判断输入结束。请高手指点一下
多谢 | N***m 发帖数: 4460 | 2 not sure what you are asking for. perhaps strtok function can do this kind
of job. http://www.cplusplus.com/reference/clibrary/cstring/strtok/
【在 a********e 的大作中提到】 : 单词和数字是用space分隔的 : getline(cin,str,' ')倒是一次可以读入一个,但是只能存储为string类型 : 。而且但是我不知道怎么判断输入结束。请高手指点一下 : 多谢
| a********e 发帖数: 508 | 3 you are right! however, it works on char sequence, which is a little
inconvinient for me. thanks anyway
【在 N***m 的大作中提到】 : not sure what you are asking for. perhaps strtok function can do this kind : of job. http://www.cplusplus.com/reference/clibrary/cstring/strtok/
| c**b 发帖数: 2999 | 4 use sscanf
char s[2000],b[200];
int a,c;
cin.getline(s,2001);
sscanf(s, "%d %s %d", &a, b, &c);
【在 a********e 的大作中提到】 : 单词和数字是用space分隔的 : getline(cin,str,' ')倒是一次可以读入一个,但是只能存储为string类型 : 。而且但是我不知道怎么判断输入结束。请高手指点一下 : 多谢
| s*w 发帖数: 729 | 5 判断输入结束
while (!getline(cin,str,' ').eof()) {
}
string 转数字方法很多,随便 google, 比如
istringstream stream (s);
double t;
stream >> t;
【在 a********e 的大作中提到】 : 单词和数字是用space分隔的 : getline(cin,str,' ')倒是一次可以读入一个,但是只能存储为string类型 : 。而且但是我不知道怎么判断输入结束。请高手指点一下 : 多谢
|
|