【发布时间】:2025-11-25 15:10:02
【问题描述】:
我认为有一些微不足道的非常愚蠢的错误,但我无法确定它。有什么建议吗?
string stuff = "5x^9";
istringstream sss(stuff);
double coeff;
char x, sym;
int degree;
sss >> coeff >> x >> sym >> degree;
cout << "the coeff " << coeff << endl;
cout << "the x " << x << endl;
cout << "the ^ thingy " << sym << endl;
cout << "the exponent " << degree << endl;
输出:
the coeff 0
the x
the ^ thingy
the exponent 1497139744
我想应该是的
the coeff 5
the x x
the ^ thingy ^
the exponent 9
【问题讨论】:
-
无法复制 ideone.com/CH8wLu 。正如我在您的previous question 中所问的,您确定原始字符串不包含任何空格吗?
-
@Bob__ 肯定 100%,我的输入是“5x^9”,完全没有空格
-
@Bob__ 但我发现它对你有用!那怎么了??
-
这似乎相关:*.com/questions/19725070/…。 Here 我可以重现您的问题,而 here 将
x更改为z,它可以被解析。
标签: c++ string stream istringstream sstream