鉴于std :: string的所有方法,我已经 永远不必使用strtok()。 此致, 拉里Not in the same sense as the "C" strtok().You can use c_str() to create a "C" nul-terminatedstring from a std::string, then use strtok() onthat 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''venever had to use strtok() with them.Regards,Larry 只想指出: 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 withthat name, seeing as how names beginning with "str" followed by alower case letter are reserved in many contexts in C++. And in allcontexts 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 KleinHome: http://JK-Technology.ComFAQs forcomp.lang.c http://www.eskimo.com/~scs/C-faq/top.htmlcomp.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 只想指出: 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>) thatdidn''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. 此致, 拉里Regards,Larry 这篇关于C ++字符串类tokenizer方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-07 02:43