C++ expected constant expression

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


        
8条回答
  •  旧巷少年郎
    2020-11-30 11:07

    The line float x[size][2] won't work, because arrays have to be allocated at compile time (with a few compiler-specific exceptions). If you want to be able to easily change the size of the array x at compile time, you can do this:

     #define SIZE 100
     float x[SIZE][2];
    

    If you really want to allocate the array based on information you only have at runtime, you need to allocate the array dynamically with malloc or new.

提交回复
热议问题