split string包含特殊标记? [英] split string contain special token?
问题描述
全部:
我想实现一个函数(使用std :: string和std :: vector)
将包含特殊标记的字符串拆分为vector。
例如:
string =" alex delia john"
==>
vector [0] =" alex";
vector [1] =" delia";
vector [2] =" john" ;;
我想使用一些stl算法库函数,但我不知道哪个
算法函数是合适的。
谢谢!
Alex 2005.01.12
Hi, all:
I want to implement a function (using std::string and std::vector)
split a string contain special token into vector.
eg:
string = "alex delia john"
==>
vector[0] = "alex";
vector[1] = "delia";
vector[2] = "john";
I want use some stl algorithms library function,but I don''t kown which
algorithms function is suitable.
Thanks !
Alex 2005.01.12
推荐答案
ze ******* @ gmail.com 写道:
全部:
我想实现一个功能(使用std :: string和std :: vector)
将包含特殊标记的字符串拆分为vector。
例如:
string =" alex delia john"
> ==>
vector [0] =" alex" ;;
vector [1] =" delia " ;;
vector [2] =" john";
我想使用一些stl算法库函数,但我不知道哪种算法函数适合。
谢谢!
Hi, all:
I want to implement a function (using std::string and std::vector)
split a string contain special token into vector.
eg:
string = "alex delia john"
==>
vector[0] = "alex";
vector[1] = "delia";
vector[2] = "john";
I want use some stl algorithms library function,but I don''t kown which
algorithms function is suitable.
Thanks !
您可以尝试新的Boost字符串算法库:
http://www.boost.org/doc/html/string....html#id576776
Jonathan
You might try the new Boost String Algorithm library:
http://www.boost.org/doc/html/string....html#id576776
Jonathan
我知道boost字符串可以分割这样的字符串文字,但我想要
使用stl实现''split''
谢谢你的回复!
I know boost string can split such string literal,but I want to
implement ''split'' using stl.
Thanks your reply!
< ze ******* @ gmail.com>在消息中写道
<ze*******@gmail.com> wrote in message
我知道boost字符串可以拆分这样的字符串文字,但是我想用stl实现''split''。
I know boost string can split such string literal,but I want to
implement ''split'' using stl.
怎么样 -
string Str =" alex delia john";
std :: istringstream iss(Str);
std :: vector< string> vec((std :: istream_iterator< string>(iss)),
std :: istream_iterator< string>());
HTH,
Sharad
How about this -
string Str = "alex delia john";
std::istringstream iss( Str );
std::vector<string> vec( (std::istream_iterator<string>(iss)),
std::istream_iterator<string>() );
HTH,
Sharad
这篇关于split string包含特殊标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!