c++ - 如何在 C++ 中将一个字符串分成多个字符串?
问题描述
首先,我将解释我要存档的内容:假设以下字符串, 25a0: ebfffa01 bl dac <abort@plt>
(注意第一个字符之前有空格),那么我的目标是获得以下输出:
25a0:
ebfffa01
bl
dac
<abort@plt>
问题是字符串可以被几个(连续的)空格分隔,因此我当前的解决方案无法正常工作:
vector<vector<string>> getStructuredContent(vector<string> content) {
vector<vector<string>> structuredContent;
for(string line: content) {
char space_char = ' ';
vector<string> words{};
stringstream sstream(line);
string word;
while (getline(sstream, word, space_char)){
if(word != "")
words.push_back(word);
}
structuredContent.push_back(words);
}
return structuredContent;
}
上面字符串的输出当前是:
25a0: ebfffa01
bl dac
<abort@plt>
也许有人知道如何解决这个问题?
解决方案
推荐阅读
- docker - 保存 docker 镜像的当前状态并导出到另一台服务器
- css - 拉伸窗口时 div 超出边界的 CSS 错误
- javascript - 使用 Vanilla JS 反转动画的正确方法?
- ambari - 升级 Ambari 服务器失败,出现 AttributeError:“NoneType”对象没有属性“title”
- mongodb - 我们可以在 Mongodb 函数中编写聚合查询吗?
- c++ - 在矩阵和向量的代理类中重载赋值运算符?
- angular - 使用 CircleCI 和 AWS S3 为 Angular 项目实施 CICD 管道
- android - 使用 ZBar 在运行 Android 6.1 的嵌入式设备上检测条形码失败
- html - 如何使用 AngularJs 中的 ng-repeat 使配方仅出现在它所属的类别下方?
- datastage - 基于数据阶段场景的需求