C++ - char* vs. string*

前端 未结 7 1524
清歌不尽
清歌不尽 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, char* is the pointer to an array of character, which is a string. string * is the pointer to an array of std::string (which is very rarely used).

    string *name = "name"; 
    

    "name" is a const char*, and it would never been converted to a std::string*. This will results compile error.

    The valid declaration:

    string name = "name";
    

    or

    const char* name = "name"; // char* name = "name" is valid, but deprecated
    

提交回复
热议问题