Anybody have any idea how to convert strings to char*. I am writing a program that involves using some of the unix system calls (execv()) and I get input from the user with strings, but these functions take char* as parameters!!!
PLEASE HELP!!
Anybody have any idea how to convert strings to char*. I am writing a program that involves using some of the unix system calls (execv()) and I get input from the user with strings, but these functions take char* as parameters!!!
PLEASE HELP!!
std::string has a member function c_str() that returns a const char* rep of the string object.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
One solution is strcpy() and c_str() as the other member has mentioned.
Kuphryn
all my attempts of using c_str() have ended in an unhandled exception
and the problem with the execv() call is that my input from the user is put into an array argv[] the call would be
execv(argv[0], argv, 0);
making the second parameter argv.c_str() gives me errors as well.
Where's the string object?
...
std::string a;
a.c_str()
The command line arguments aren't string objects
"He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson
string buffer;
string argv[10];
cout << "enter agruments: ";
getline.(cin, buffer);
buffer gets split up into argv, for example if buffer was:
/bin/ls -alg
argv[0] = /bin/ls
argv[1] = -alg
then I want to call exec using those as parameters
but I can't write
execv(argv[0].c_str(), argv.c_str(), (char*)0);
because I get errors for the argv.c_str()
execv(argv[0].c_str(), argv.c_str(), (char*)0);
you're not indexing an element of argv. Also, what you're doing still makes no sense = | You're trying to command line stuff, right? But you're declaring argv as an array of string objects.
?
"He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]