convert string to const char

Hello. for my program I need to change a string into a const char ( for opendir )

1
2
3
4
5
6
7
...
string uhome=getenv("HOME");
string dir1="/Desktop";
const char *findir=uhome+dir1;
const char *curdir=findir;
dir=opendir(curdir);
...


thanks in advance

and yes i have searched the forums :S
string::cstr
1
2
3
...
string findir = uhome + dir1;
dir = opendir(findir.c_str());
closed account (zb0S216C)
Branflakes91093 has the right idea. Using the method: c.str( ), which is a member method of string, will give you a C-string equivalent of the string object.

See here: http://www.cplusplus.com/reference/string/string/c_str/
Last edited on
Thank you :)
Topic archived. No new replies allowed.