如何测试字符串运算符>是否解析了坏类型并跳过它
stringstream
"2.832 1.3067 nana 1.678"
strings
doubles
stringstream
failbit
string a("2.832 1.3067 nana 1.678"); stringstream parser; parser.str(a); for (int i = 0; i < 4; ++i) { double b; parser >> b; if (parser.fail()) { std::cout << "Failed!" << std::endl; parser.clear(); } std::cout << b << std::endl; }
2.8321.3067Failed!0Failed!0
failbit