有什么方法可以使用 istringstream 读取嵌入空字符的字符串?例如,如果我有一个字符数组“125 320 512 750 333\0 xyz”。有什么方法可以在空字符之后得到“xyz”?
#include <iostream>
#include <sstream>
using namespace std;
int main() {
std::string stringvalues = "125 320 512 750 333\0 xyz";
cout << "val: " << stringvalues << endl;
std::istringstream iss (stringvalues);
for (int n=0; n<10; n++)
{
string val;
iss >> val;
std::cout << val << '\n';
}
return 0;
}
这是一个从 cplusplus.com 修改的示例。我想得到空字符之后的部分,我很好奇在不知道 char 数组的确切长度的情况下是否可以得到它。提前致谢。