Copy Code code as follows:
String--> const Char
String str2ch;
Str2ch.c_str ();
//=============================
String--> char *
Convert first to const char and then char *
Char Targetfile[strlen (TORRENTFILENAMEDOWN.C_STR ())];
strcpy (Targetfile,torrentfilenamedown.c_str ()); Change Type const char to char *
//=============================
char *--> string
int main (int argc, char *argv[])
String Strcommand_down;
Strcommand_down.assign (Argv[1],strlen (argv[1)); Char Array turn string
Mans strcpy
Copy Code code as follows:
#include <string.h>
Char *strcpy (char *dest, const char *SRC);
Attached: pointer constants, constant pointers
What is a pointer constant? A pointer constant is a constant of pointer type.
Example: Char *const name1= "John";
name1= "ABC"; Error, name1 pointer, cannot change, a pointer type variable, storing address, so cannot assign ' ABC ' address to name1
char * name2= name1; OK
What is a constant pointer? A constant pointer is a pointer to a constant, and the value of the pointer can be changed, and the contents of the address that the pointer refers to are constants that cannot be changed.
Example: const char *name1= "John";
Char s[]= "ABC"; Name1=s; Correct, the address that name1 store can change
char * name2= name1; No, because Name2 and name1 store the same address, if the content of the name2 address is changed, then the content of NAME1 also changed, then NAME1 is no longer a pointer to the constant.
One word, close to which one can not change!