#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
int main() {
int count = 0;
float sum = 0;
float maximum = -1000000;
std::ifstream points;
int size = 100;
float x[size][2]; // <<< error
while (count < size) {
points >> x[count][0];
points >> x[count][1];
count++;
}
}
This program is giving me expected constant expression error on the line where I declare float x[size][2]. Why?
That doesn’t work because declared arrays can’t have runtime sizes. Try a vector:
Or use new
If you don’t have C++11 available, you can use
boost::arrayinstead ofstd::array.If you don’t have boost available, make your own array type you can stick into vector
For easing the syntax of
new, you can use anidentitytemplate which effectively is an in-place typedef (also available inboost)If you want, you can also use a vector of
std::pair<float, float>