我想从一个字符串中“提取”信息。该字符串始终格式为int int char
。使用std :: sscanf和std :: string的C++
我花了很长时间在这个上,检查了“每个”这个网站和谷歌我发现的例子,没有用。编译了一些例子,但崩溃了(没有溢出)。
这里是目前,它编译但崩溃。
// Data
string str = "53 25 S";
int num1;
int num2;
char type3;
// Read values
sscanf(str.c_str(),"%i %i %c",num1,num2,type3);
(在标准头
<sstream>
声明)是'的std :: istringstream'考虑会更好? –是的。并有strtok()的考虑,但为此,我想尽可能简单。 –