c++ - Best way to create a C String -
I am currently using
char * thisvar = "stringcontenthere"; To declare a string in C.
What is the best way to declare a string in C?
And how about generating a C from C-string to C ++ - strings?
It depends on how you will use the string in C
- Named continuous: your
four * str = "string";
The method is ok (butshould be four constellation
) - the data must be sent to the subfunction, but it is not used after the calling function. Will:
four str [] = "string";
- Used after the data function, it is declared in the exit:
four * str = strdup ("string");
, and make sure that it becomes thefree
eventually.
If it does not cover it, try adding more details to your answer.
Comments
Post a Comment