我Visual Studio 2010 Pro
在Windows 7 64bit
机器上使用,我想count
(从<algorithm>
标题)在valarray
:
int main()
{
valarray<bool> v(false,10);
for (int i(0);i<10;i+=3)
v[i]=true;
cout << count(&v[0],&v[10],true) << endl;
// how to define the return type of count properly?
// some_type Num=count(&v[0],&v[10],true);
}
上面程序的输出是正确的:
4
但是,我想将值分配给变量并使用int
导致编译器警告精度损失的结果。由于valarray
没有迭代器,我无法弄清楚如何使用iterartor::difference_type
.
这有可能吗?