10

std::vector如何转换为std::string

 3 years ago
source link: http://www.banbeichadexiaojiubei.com/index.php/2021/01/01/stdvector%e5%a6%82%e4%bd%95%e8%bd%ac%e6%8d%a2%e4%b8%bastdstring/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
2021年1月1日2021年1月1日 | by YoungTimes | No comments

std::vector如何转换为std::string

有没有一种方法将std::vector<char>方便快速的转换为std::string呢?

std::string提供了如下的构造函数:

template<class InputIterator> string (InputIterator begin, InputIterator end);
template<class InputIterator> string (InputIterator begin, InputIterator end);

通过它可以很方便的使用std::vector<char>构造std::string。

std::vector<char> v;
std::string str(v.begin(), v.end());
std::vector<char> v;
std::string str(v.begin(), v.end());

https://stackoverflow.com/questions/5115166/how-to-construct-a-stdstring-from-a-stdvectorchar

除非注明,否则均为[半杯茶的小酒杯]原创文章,转载必须以链接形式标明本文链接

本文链接:http://www.banbeichadexiaojiubei.com/index.php/2021/01/01/stdvector%e5%a6%82%e4%bd%95%e8%bd%ac%e6%8d%a2%e4%b8%bastdstring/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK