C++ - char* vs. string*

前端 未结 7 1525
清歌不尽
清歌不尽 2021-02-04 03:28

If I have a pointer that points to a string variable array of chars, is there a difference between typing:

char *name = \"name\";

7条回答
  •  梦谈多话
    2021-02-04 03:51

    Yes, the second one isn't valid C++! (It won't compile).

    You can create a string in many ways, but one way is as follows:

    string name = "name";
    

    Note that there's no need for the *, as we don't need to declare it as a pointer.

提交回复
热议问题