Converting a C-style string to a C++ std::string

后端 未结 6 1510
梦如初夏
梦如初夏 2020-12-14 00:42

What is the best way to convert a C-style string to a C++ std::string? In the past I\'ve done it using stringstreams. Is there a better way?

6条回答
  •  离开以前
    2020-12-14 01:14

    Check the different constructors of the string class: documentation You maybe interested in:

    //string(char* s)
    std::string str(cstring);
    

    And:

    //string(char* s, size_t n)
    std::string str(cstring, len_str);
    

提交回复
热议问题