c++ - 从 char * 中的整数填充 vector<int>

标签 c++ stl vector

char *values = "   3   1   4 15";

vector<int> array;

我想用值填充数组,

3,1,4,15

有没有一种巧妙的方法可以使用 STL 复制算法来做到这一点?

最佳答案

确实有:

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

关于c++ - 从 char * 中的整数填充 vector<int>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/372453/

相关文章:

c++ - 数据抽象和封装的好处

c++ - 隐式 “using namespace std” 没有写在源代码中

java - 加密程序

c++ - 基于模板参数推导利用的 STL 算法名称可解析或未定义

c++ - SIGABRT on std::ifstream关闭

c++ - STL vector 如何提供随机访问

c++ - 堆栈容器适配器结构

c++ - 链式操作的重载 +=

r - 查找最近的较小数字

用模式替换 R 中的字符串并替换两个向量