So this must be something really silly, but I'm getting an error with this code.
What could be going wrong, the operands <, > also don't work. Does one use vectors differently? When I try y.at(1) = 10; it says expression must have class type...?
#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;
}
For context I'm trying to test for run times. Was using std::array at first, but it seems like that doesn't work with large array sizes, so I decided to try out vectors.
Used http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c4027/C-Tutorial-A-Beginners-Guide-to-stdvector-Part-1.htm as a reference, but it seems like although I'm doing the exact same thing, something is not working.
See Question&Answers more detail:os