puzzlecracker said:
let's say have a string: string str="arg1 arg2 arg3";
I need to convert it to
char **s where s={arg1, arg2,arg3, NULL};
has anyone encountered this problem and has fast solution?
Thanks
You've not been reading recent posts, redfloyd posted a similar solution
which
I've shamelessly adapted....Of course, you might use strtok() to token your
original
string & create the array of what-have-yous.
#include <string>
#include <sstream>
#include <iterator>
#include <vector>
int main(int argc, char* argv[])
{
char* ARGS[100];
int ARGSC = 0;
std::istringstream is(" arg1 arg2 arg3 arg4 arg5 " );
for ( std::istream_iterator<std::string> it(is) ;
it!=std::istream_iterator<std::string>() ; ++it, ++ARGSC)
{
std::string s=*it;
ARGS[ARGSC]= strdup( s.c_str() );
}
return 0;
}