I’ve appends some elements in my list
std::list<std::string> dirList2;
//Code
dirList2.push_back(findData.cFileName);
copy(dirList2.begin(), dirList2.end(),std::ostream_iterator<std::string> (std::cout,"\n"));
Everything work, i can view this items,
Now i want to assign the first elem of my list to a char* .
Can someone help me please ? i’dont know how to do it
If I understood well what you want then you can do it like this:
Be careful, though. The C string which variable
spoints to is owned by the string object sitting on your list. If the list goes out of scope or you remove the element from your list, then the C string will be released by thestd::string‘s destructor and yourspointer will not be valid.If you want to manipulate the C string beyond the liftime of the
std::stringobject than you can do sth. like this:But it’s usually better to use
std::stringinstead of raw C pointers, unless you have no choice.