填充向量< int>从char *中的整数 [英] Populate a vector<int> from integers in a char *
本文介绍了填充向量< int>从char *中的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
char *values = " 3 1 4 15";
vector<int> array;
我想使用值填充数组,
3,1,4,15
使用stl复制算法有没有光滑的方法?
Is there a slick way to do it with the stl copy algorithm?
推荐答案
确实存在:
std::istringstream iss(values);
std::copy(std::istream_iterator<int>(iss),
std::istream_iterator<int>(),
std::back_inserter(array));
这篇关于填充向量< int>从char *中的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文