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 (but should 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 the free eventually.

If it does not cover it, try adding more details to your answer.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -