我正在尝试解析从文件中读取的一些输入字符串反应,其公式为:2W+B=8A+10Z,我只需要拆分并提取整数值以将它们放入向量中,即与此反应相关联的向量为:[2 1 8 10]。我考虑了很多方法:
这是我的尝试:
std::strtok(),isdigital(),find_first_of()
但它们都不能用于整数值...有人能帮忙吗?这是我的尝试:
int main()
{
std::string input;
std::getline(std::cin, input);
std::stringstream stream(input);
while(1) {
int n;
stream >> n;
char * pch;
pch = strtok (input," ");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,.");
}
}
}