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

后端 未结 6 1512
梦如初夏
梦如初夏 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:07

    You can initialise a std::string directly from a c-string:

    std::string s = "i am a c string";
    std::string t = std::string("i am one too");
    

提交回复
热议问题