C++ expected constant expression

前端 未结 8 1473
日久生厌
日久生厌 2020-11-30 10:42
#include 
#include 
#include 
#include 
#include 
using std::ifstream;
using namespace std;
         


        
8条回答
  •  执笔经年
    2020-11-30 11:29

    The size of an automatic array must be a compile-time constant.

     const int size = 100;
     float x[size][2];
    

    If the size weren't known at compile-time (e.g entered by the user, determined from the contents of the file), you'd need to use dynamic allocation, for example:

    std::vector > x(somesize);
    

    (Instead of a pair, a dedicated Point struct/class would make perfect sense.)

提交回复
热议问题