A C string is a null-terminated character array. Thus, to convert your character array to a C string, simply append a null "\0" to the end of it. Note however that if your character array is in argv[1], then it will already be null-terminated because argv from main() is always an array of strings. If you want to use a C++ string, then simply declare one one passing the aforementioned C string to the constructor:
-
#include <string>
-
int main(int argc, char * argv[])
-
{
-
std::string str(argv[1]); // str: C++ string containing the characters of argv[1]
-
...
-
Thanks A lot.
can u tell me why the value of result is 3 at the time of debuging.
please see the below code for renameing afile i want to use rename() of stdio.h
const char *oldname=argv[1];
const char *newname="input.docx";
int result=rename(oldname,newname);
cout<<"result "<<result;
rename() return -1 ? not renamed please tell me why? there is no compiler error, but its not renaming