本文介绍了c ++标记化std字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
如何在 C++ 中标记字符串?
你好,我想知道如何用 strtok 标记一个 std 字符串
Hello I was wondering how I would tokenize a std string with strtok
string line = "hello, world, bye";
char * pch = strtok(line.c_str(),",");
我收到以下错误
error: invalid conversion from ‘const char*’ to ‘char*’
error: initializing argument 1 of ‘char* strtok(char*, const char*)’
我正在寻找一种快速简便的方法,因为我认为这不需要太多时间
I'm looking for a quick and easy approach to this as I don't think it requires much time
推荐答案
我总是使用 getline
来处理此类任务.
I always use getline
for such tasks.
istringstream is(line);
string part;
while (getline(is, part, ','))
cout << part << endl;
这篇关于c ++标记化std字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!