整数向量
vector of integers
我想把一个向量转换成一个整数。我可以用
输出向量vector <int> iV;
iV.push_back(3);
iV.push_back(8);
iV.push_back(6);
copy(iV.begin(),iV.end(),ostream_iterator<int>(cout,""))
但是我怎么把它变成整型呢?
编辑:使用stringstream对我正在做的事情很好。我确实想通过cout看看它到底是什么样子。我不想要精确的整型,我指的是一个整型,所以在我的例子中,它是一个等于386的整型。谢谢大家的帮助,非常感谢。
将其写入stringstream,然后像这样读取:
std::stringstream strStream;
copy(iV.begin(),iV.end(),ostream_iterator<int>(strStream,""));
int myInt;
strStream >> myInt;
我不确定这是否是你的意思,但你可以这样做:
int * ip = &iv[0];
,然后访问ip[0]
, ip[1]
等
int x;
for(vector<int>::const_iterator i = iV.begin(); i != iV.end(); i++)
x = *i;
试试这样:
int total = 0;
for(vector<int>::const_iterator i = iV.begin(); i != iV.end(); ++i)
total = total*10 + *i;
相关文章:
- C++:如何循环通过向量中的整数元素
- 添加存储在向量中的大整数的函数出现问题
- C ++中的StringStream有助于使用向量从字符串中提取逗号分隔的整数,而不是空格分隔的整数,为什么?
- 使用英特尔内联函数将打包的 8 位整数乘以浮点数向量
- C++ 如何比较n个排序的整数向量以找到互元素?
- 必须首先打印向量 v1 中最接近整数 x 的数字<int>
- 如何将整数字符串转换为整数的二维向量?
- 如何将整数向量值插入字符向量
- 如何使用 STL 算法将整数向量转换为字符串向量?
- 使用192/256位整数求和无符号64位整数向量的点积的最快方法
- 查找多个向量之间的公共元素(无整数元素)
- 如何将整数向量插入到键中,标准::映射的值
- 整数对的向量转化为整数向量的向量
- 如何组合两个整数向量
- C++中整数向量的序列化/反序列化
- 如何从C++中的值向量构造整数<bool>值
- 使用整数初始化列表初始化长双精度的向量
- 将向量整数拆分为这些数字的整数
- 如何访问映射的向量(整数和字符串的向量)
- 将带有时间戳的向量整数连接为C++中的字符串