内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用
我有一系列存储在单个数组中的字符串,用空值分隔(例如['f','o','o','\ 0','b','a','r',' 0'...]),我需要把它分成一个std::vector<std::string>
或类似的东西。
我可以只写一个10行循环来使用std::find
或strlen
,但是我想知道是否有一个更简单来做到这一点
const char* p = str;
std::vector<std::string> vector;
do {
vector.push_back(std::string(p));
p += vector.back().size() + 1;
} while ( // whatever condition applies );