How to duplicate string tocken to char */char array
pHere I am trying to copy string tocken to char pointer as below:/p
precode#include lt;iostreamgt; #include lt;cstringgt; #include
lt;stringgt; #include lt;boost/tokenizer.hppgt; using namespace std; using
namespace boost; int main(int, char**) { string text = token test string;
char *word; char_separatorlt;chargt; sep( );
tokenizerlt;char_separatorlt;chargt;gt; tokens(text, sep); int i=0; for
(const autoamp; t : tokens) { cout lt;lt; t lt;lt; . lt;lt; endl; word[i]
=(const char *)strdup(t); // Error i++; } } /code/pre perror is :
test.cpp:18:40: error: cannot convert 'const std::basic_string' to 'const
char*' for argument '1' to 'char* strdup(const char*)'/p
No comments:
Post a Comment