C++ expected constant expression

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


        
8条回答
  •  生来不讨喜
    2020-11-30 11:11

    Because it expected a constant expression!

    Array dimensions in C (ignoring C99's VLAs) and C++ must be quantities known at compile-time. That doesn't mean just labelled with const: they have to be hard-coded into the program.

    Use dynamic allocation or std::vector (which is a wrapper around dynamic array allocation) to determine array sizes at run-time.

提交回复
热议问题