I'm trying to declare an array with size of non-constant. g++ compiler was ok but CC compiler asked me to define a constant one. Here is an abstract of code:
1 2 3 4
getline(fin,tmp);
int filenum = atoi(tmp.c_str());
Mail* mailPtr[filenum];
The error is:
Error: An integer constant expression is required within the array subscript operator.
g++ is not a conforming C++ compiler unless one of the options --std=c++11 or --std=c++0x is used.
Or for obsolete C++ either --std=c++98 or --ansi.
1 2 3 4 5 6 7
getline(fin,tmp);
int filenum = atoi(tmp.c_str());
// atoi() may fail; you need to add a check here
// Mail* mailPtr[filenum];
std::vector<Mail*> mailPtr(filenum) ;