相关疑难解决方法(0)

是否可以在for循环中声明两个不同类型的变量?

是否可以在C++的for循环的初始化主体中声明两个不同类型的变量?

例如:

for(int i=0,j=0 ...
Run Code Online (Sandbox Code Playgroud)

定义了两个整数.我可以在初始化主体中定义a int和a char吗?怎么做?

c++ scope for-loop declaration

223
推荐指数
4
解决办法
16万
查看次数

C++的隐藏功能?

当涉及到"问题线"的"隐藏特征"时,没有C++的爱吗?想我会把它扔出去.C++的一些隐藏功能是什么?

c++ hidden-features

114
推荐指数
38
解决办法
8万
查看次数

c ++在for循环中初始化2个不同的迭代器

可能重复:
我可以在for循环的初始化中声明不同类型的变量吗?

我想在c ++中有一个for循环,它在初始化中构造了两种不同类型的向量迭代器.

这是我想要的大致想法:

std::vector<double> dubVec;
std::vector<int> intVec;
double result = 0;

dubVec.push_back(3.14);
intVec.push_back(1);

typedef std::vector<int>::iterator intIter;
typedef std::vector<double>::iterator dubIter;

for (intIter i = intVec.begin(), dubIter j = dubVec.begin(); i != intVec.end(); ++i, ++j)
{
  result += (*i) * (*j);
}
Run Code Online (Sandbox Code Playgroud)

任何人都知道在这种情况下要做的标准是什么?我不能只为intVec使用double的向量,因为我正在寻找一个通用的解决方案.[即我可能有一些函数f,它将int加倍,然后计算f(*i)*(*j)]

c++ iterator initialization

14
推荐指数
2
解决办法
3万
查看次数