C ++字符串类tokenizer方法? [英] C++ string class tokenizer method?
问题描述
我是模糊的,还是确实C ++字符串类
没有定义标记器方法?我已经定义了我自己的函数[
我已经发布到comp.sources.d],但我更愿意使用
标准函数(如果有的话)。 />
谢谢
Bhat
Is it that I am blurry eyed, or is it indeed that the C++ string class
has no tokenizer method defined? I have defined my own functions [that
I have posted to comp.sources.d], but I would prefer to use the
standard functions, if available.
Thanks
Bhat
推荐答案
Generic Usenet Account写道:
Generic Usenet Account wrote:
我是模糊的,还是C ++字符串类确实没有定义标记器方法?我已经定义了我自己的函数[
我已发布到comp.sources.d],但我更愿意使用
标准函数(如果有的话)。
谢谢
Bhat
Is it that I am blurry eyed, or is it indeed that the C++ string class
has no tokenizer method defined? I have defined my own functions [that
I have posted to comp.sources.d], but I would prefer to use the
standard functions, if available.
Thanks
Bhat
与C不同的意思strtok()。
您可以使用c_str()创建C。 nul-terminated
来自std :: string的
字符串,然后在
上使用strtok()表示以nul结尾的字符串。
char * cstr = strdup(cppstr.c_str());
//在''cstr'上使用strtok()
//然后free()'' cstr''
C ++字符串类有很多解析方法:
find(),find_first_of(),find_first_not_of(),
find_last_of(),find_last_not_of(),rfind(),
replace(),swap(),substr()等等......
>
鉴于std :: string的所有方法,我已经
永远不必使用strtok()。
此致,
拉里
Not in the same sense as the "C" strtok().
You can use c_str() to create a "C" nul-terminated
string from a std::string, then use strtok() on
that nul-terminated string.
char * cstr = strdup(cppstr.c_str());
// use strtok() on ''cstr''
// then free() ''cstr''
The C++ string class has many methods for parsing:
find(), find_first_of(), find_first_not_of(),
find_last_of(), find_last_not_of(), rfind(),
replace(), swap(), substr(), etc, etc, etc...
Given all of the methods of std::string, I''ve
never had to use strtok() with them.
Regards,
Larry
2005年6月16日星期四00:08:20 GMT,Larry I Smith
< LA *********** @ verizon.net>在comp.lang.c ++中写道:
On Thu, 16 Jun 2005 00:08:20 GMT, Larry I Smith
<la***********@verizon.net> wrote in comp.lang.c++:
Generic Usenet Account写道:
Generic Usenet Account wrote:
是我模糊不清,还是确实是C ++字符串类
没有定义tokenizer方法?我已经定义了我自己的函数[
我已发布到comp.sources.d],但我更愿意使用
标准函数(如果有的话)。
谢谢
Bhat
与C不同的意思strtok()。
你可以使用c_str()来创建一个C。来自std :: string的nul-terminated
字符串,然后使用strtok()
以nul结尾的字符串。
char * cstr = strdup(cppstr.c_str() );
Is it that I am blurry eyed, or is it indeed that the C++ string class
has no tokenizer method defined? I have defined my own functions [that
I have posted to comp.sources.d], but I would prefer to use the
standard functions, if available.
Thanks
Bhat
Not in the same sense as the "C" strtok().
You can use c_str() to create a "C" nul-terminated
string from a std::string, then use strtok() on
that nul-terminated string.
char * cstr = strdup(cppstr.c_str());
只想指出:
1.没有C或C ++标准库函数strdup( )。
2.使用
这个名称创建自己的函数是不明智的,看看名称以str开头的名称。接下来是一个
小写字母在C ++的许多上下文中保留。并且在所有
上下文中作为C中的函数名。
//在''cstr'上使用strtok()
//然后free()' 'cstr''
C ++字符串类有很多解析方法:
find(),find_first_of(),find_first_not_of(),
find_last_of(),find_last_not_of(), rfind(),
replace(),swap(),substr()等等...
给定std :: string的所有方法,我'' ve
从来没有和他们一起使用strtok()。
问候,
拉里
Just wanted to point out that:
1. There is no C or C++ standard library function strdup().
2. It is rather inadvisable to create a function of your own with
that name, seeing as how names beginning with "str" followed by a
lower case letter are reserved in many contexts in C++. And in all
contexts as a function name in C.
// use strtok() on ''cstr''
// then free() ''cstr''
The C++ string class has many methods for parsing:
find(), find_first_of(), find_first_not_of(),
find_last_of(), find_last_not_of(), rfind(),
replace(), swap(), substr(), etc, etc, etc...
Given all of the methods of std::string, I''ve
never had to use strtok() with them.
Regards,
Larry
-
Jack Klein
主页: http:// JK- Technology.Com
常见问题解答
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp .lang.c ++ http://www.parashift.com/c++-faq -lite /
alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jack Klein写道:
Jack Klein wrote:
2005年6月16日星期四00:08:20 GMT,Larry I Smith
< la ********** *@verizon.net>在comp.lang.c ++中写道:
On Thu, 16 Jun 2005 00:08:20 GMT, Larry I Smith
<la***********@verizon.net> wrote in comp.lang.c++:
Generic Usenet Account写道:
Generic Usenet Account wrote:
是我模糊不清,还是确实是C ++字符串类
没有定义tokenizer方法?我已经定义了我自己的函数[
我已发布到comp.sources.d],但我更愿意使用
标准函数(如果有的话)。
谢谢
Bhat
与C的含义不同。 strtok()。
你可以使用c_str()来创建一个C。来自std :: string的nul-terminated
字符串,然后使用strtok()
以nul结尾的字符串。
char * cstr = strdup(cppstr.c_str() );
Is it that I am blurry eyed, or is it indeed that the C++ string class
has no tokenizer method defined? I have defined my own functions [that
I have posted to comp.sources.d], but I would prefer to use the
standard functions, if available.
Thanks
Bhat
Not in the same sense as the "C" strtok().
You can use c_str() to create a "C" nul-terminated
string from a std::string, then use strtok() on
that nul-terminated string.
char * cstr = strdup(cppstr.c_str());
只想指出:
1.没有C或C ++标准库函数strdup()。
Just wanted to point out that:
1. There is no C or C++ standard library function strdup().
也许,但我从来没有见过C < string.h中> (又名< cstring>)
没有strdup() - 至少在MS Windows,Linux和& Solaris。
strtok(),strdup(),strlen(),strcpy()等都是有效的C
函数可以在C ++中使用< string.h中>或者< cstring>
包含
。
2.使用
创建自己的功能是不明智的如何以str开头的名称后跟一个小写字母在C ++的许多上下文中保留。在所有
上下文中作为C中的函数名。
Maybe, but I''ve never seen a "C" <string.h> (aka <cstring>) that
didn''t have a strdup() - at least on MS Windows, Linux, & Solaris.
strtok(), strdup(), strlen(), strcpy(), etc are all valid "C"
functions that may be used in C++ when <string.h> or <cstring>
is included.
2. It is rather inadvisable to create a function of your own with
that name, seeing as how names beginning with "str" followed by a
lower case letter are reserved in many contexts in C++. And in all
contexts as a function name in C.
//在''cstr'上使用strtok()
//然后free()' 'cstr''
C ++字符串类有很多解析方法:
find(),find_first_of(),find_first_not_of(),
find_last_of(),find_last_not_of(), rfind(),
replace(),swap(),substr()等等...
给定std :: string的所有方法,我'' ve
永远不必使用strtok()。
问候,
Larry
// use strtok() on ''cstr''
// then free() ''cstr''
The C++ string class has many methods for parsing:
find(), find_first_of(), find_first_not_of(),
find_last_of(), find_last_not_of(), rfind(),
replace(), swap(), substr(), etc, etc, etc...
Given all of the methods of std::string, I''ve
never had to use strtok() with them.
Regards,
Larry
此致,
拉里
Regards,
Larry
这篇关于C ++字符串类tokenizer方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!