C++ - 我如何拆分在名为 "result" 的字符串中保护的 3 行,并为所有 3 个字符串创建一个单行 "synonym"。 - C++
C++ - How can i split up 3 lines safed in string called "result" and create a oneline "synonym" for all 3 strings. - C++
所以,大家好。
我有一个函数,它读取磁盘驱动器序列号。
我得到这样的输出:
SerialNumber A6PZD6FA 1938B00A49382 0000000000000
(thats not my serialnumber, just the format)
所以现在,我想拆分 3 个数字或字符串,但我称之为你知道我的意思,并将其保存在三个独立的字符串中。
string a = {A6PZD6FA this value} string b = {1938B00A49382 this value} string c = {0000000000000 this value}
之后,我想为所有 3 个字符串创建一个单行“同义词”。所以我的意思是,
string synonym = 04930498SV893948AJVVVV34
像这样。
如果字符串变量中有原文,可以用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";
所以,大家好。
我有一个函数,它读取磁盘驱动器序列号。 我得到这样的输出:
SerialNumber A6PZD6FA 1938B00A49382 0000000000000 (thats not my serialnumber, just the format)
所以现在,我想拆分 3 个数字或字符串,但我称之为你知道我的意思,并将其保存在三个独立的字符串中。
string a = {A6PZD6FA this value} string b = {1938B00A49382 this value} string c = {0000000000000 this value}
之后,我想为所有 3 个字符串创建一个单行“同义词”。所以我的意思是,
string synonym = 04930498SV893948AJVVVV34
像这样。
如果字符串变量中有原文,可以用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";