c++ - Cleanest way to tokenize a std::string in C++ with the '\t' tab character as the single delimiter?
问题描述
std::vector<std::string> tokenize(std::string str) {
std::vector<std::string> tokens;
/*
// trying to figure out how to split the string up into individual token strings
//
*/
return tokens;
}
void testFunc() {
std::string text= " smoker coffee";
std::vector<std::string> tokens = tokenize(text);
for (std::string s : tokens) {
std::cout << s << std::endl;
}
}
output:
smoker
coffee
I've tried using std::getline(...) as suggested here How to split a file lines with space and tab differentiation?
but, I don't think it worked right and was tripping up over whether or not I was using the '\t' character as a delimiter correctly.
解决方案
推荐阅读
- javascript - 生成多数组的排列
- c++ - How to create a program that identifies longest substring palindrome regardless of letter casing
- javascript - 基于另一列中输入的相同值,表单提交时自动递增编号
- mysql - 将数据库从服务器复制到另一个服务器时出现mysqldump错误
- android - GridLayoutManager 为保存状态获取错误的锚位置(始终为 0),因此无法正确保存/恢复滚动位置
- java - Java Full GC - 浮动垃圾?
- webstorm - 在 WebStorm 中获取“找不到模块 'jsdom-quokka-plugin'”
- kubernetes - 获取 Kubernetes 部署的 pod 的推荐方法是什么?
- android - 上传免安装应用时出现错误 736569013
- javascript - Chrome 扩展通过 POST 将选定的文本发送到外部 API