【发布时间】:2015-08-07 06:58:51
【问题描述】:
所以这一定是非常愚蠢的事情,但我收到了这段代码的错误。
可能出了什么问题,操作数 也不起作用。是否使用不同的向量?当我尝试 y.at(1) = 10;它说表达式必须具有类类型...?
#include "stdafx.h"
#include <iostream>
#include "time.h"
#include <vector>
int main()
{
using namespace std;
const long long l = 100000;
vector <int> y[l];
long long x[l];
y[0] = 10; // Test statement results in Error.
//for (long i = 0;i < l;i++) {
// y.at(i) = i;//rand() % 100;
// x[i] = rand() % 100;
//}
clock_t t = clock();
for (long long i = 0;i < l;i++) {
long long r;
r = y[i] ^ ((x[i]^y[i]) & -(x[i] < y[i]));
/*if (x[i] < y[i]) {
r = x[i];
}
else {
r = y[i];
}*/
}
t = clock() - t;
printf("It took %d ms ", t);
return 0;
}
对于上下文,我正在尝试测试运行时间。起初使用 std::array ,但似乎不适用于大数组大小,所以我决定尝试向量。
二手 http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c4027/C-Tutorial-A-Beginners-Guide-to-stdvector-Part-1.htm 作为参考,但似乎虽然我在做完全相同的事情,但有些东西不起作用。
【问题讨论】:
-
我会指出,您没有在做与您链接到的文章“完全相同的事情”。
-
非常感谢您的帮助。