提问者:小点点

C-我如何拆分3行安全的字符串称为“结果”并为所有3个字符串创建一个在线“同义词”。-C[重复]


所以,大家好。

我有一个函数,它读取磁盘驱动器序列号。我得到这样的输出:

序列号A6PZD6FA 1938B00A493820000000000000(这不是我的序列号,只是格式)

所以现在,我想拆分3个数字或字符串,无论我怎么称呼它,你知道我的意思,并将其保存在三个独立的字符串中。

string a={A6PZD6FA this value}string b={1938B00A49382 this value}string c={0000000000000this value}

之后,我想为所有3个字符串创建一个在线“同义词”。所以我的意思是,string synonym=04930498SV893948AJVVVV34类似这样的东西。


共1个答案

匿名用户

如果字符串变量中有原始文本,则可以使用std::istringstream将其解析为组成部分:

std::string s = "SerialNumber A6PZ etc etc...";
std::istringstream iss{s};
std::string ignore, a, b, c;
if (iss >> ignore >> a >> b >> c) {
    std::string synonym = a + b + c;
    ...do whatever with synonym...
} else
    std::cerr << "your string didn't contain four whitespace separated substrings\n";

相关问题