【问题标题】:Populate a vector<int> from integers in a char *从 char * 中的整数填充 vector<int>
【发布时间】:2010-09-27 05:05:18
【问题描述】:
char *values = "   3   1   4 15";

vector<int> array;

我想用值填充数组,

3,1,4,15

stl 复制算法有没有一种巧妙的方法?

【问题讨论】:

标签: c++ stl vector


【解决方案1】:

确实有:

std::istringstream iss(values);
std::copy(std::istream_iterator<int>(iss), 
          std::istream_iterator<int>(), 
          std::back_inserter(array));

【讨论】:

  • 是的,正中目标。我觉得我已经受过更多的教育了。谢谢。
猜你喜欢
  • 1970-01-01
  • 2013-02-18
  • 1970-01-01
  • 1970-01-01
  • 2016-01-07
  • 1970-01-01
  • 2019-11-18
  • 1970-01-01
  • 2013-09-26
相关资源
最近更新 更多