将C样式字符串转换为C ++ std :: string [英] Converting a C-style string to a C++ std::string
本文介绍了将C样式字符串转换为C ++ std :: string的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将C风格字符串转换为C ++ std :: string
的最佳方法是什么?在过去,我使用 stringstream
s。有更好的方法吗?
What is the best way to convert a C-style string to a C++ std::string
? In the past I've done it using stringstream
s. Is there a better way?
推荐答案
C ++字符串有一个构造函数,可以转换C风格的字符串:
C++ strings have a constructor that lets you convert C-style strings:
char* myStr = "This is a C string!";
std::string myCppString = myStr;
这篇关于将C样式字符串转换为C ++ std :: string的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文