expression did not evaluate to a constant- c++

char ansString[sizeOfRetNum]; 

Is a Variable Length Array and is not standard in C++. Some compilers like GCC allow them as an extensions but MSVS will not compile them.

In order to get a dynamic array you will need to use a pointer and new

char* ansString = new char[sizeOfRetNum];

Or better yet, rework the function to use a std::string, which handles the memory management for you.

Leave a Comment