使用sscanf从char []中读取带空格的字符串

时间:2016-10-22 13:05:39

标签: c

我有一个字符串,我想将其拆分为变量,例如:

char[]="i 176064 Patterson";

我想通过使用sscanf来拥有:

firstword = "i"
secondword = 176064
thirdword = "Patterson"

但是secondword必须是int。

怎么可能?

编辑:

我写了这段代码:

int main()
{   char cstr[] = "i 176064 Patterson Denise 8.58 11 DEN 15788 ";
    string option,name,sername,dep;
    int studID,numofc,post;
    float gpa;
    sscanf(cstr, "%s %d %s %s %2.2f %d %s %d",option,&studID,name,sername,&gpa,&numofc,dep,&post);

}

但我收到编译错误

  

错误:无法通过'...'|

传递非平凡可复制类型'std :: string {aka class std :: basic_string}'的对象

任何想法?

0 个答案:

没有答案