使用istringstream类似的,例如:
#include <string>
#include <sstream>
int main(void)
{
std::istringstream ss("25 b");
int x; std::string bstr;
ss >> x >> bstr;
return 0;
}
// note that std:istringstream allows ss >> x, but not ss << "some value".
// if you want to support both reading and writing, use a stringstream (which would then support ss >> x as well as ss << "some value")
Run Code Online (Sandbox Code Playgroud)
使用std::stringstream:
std::stringstream myStr{"25 b"};
myStr >> *integerVar >> *charVar;
Run Code Online (Sandbox Code Playgroud)