c++ - Array size declarator, can they be calculated? VC++ -
ubernoob question: possible in ms visual c++ declare array size based upon user input?
int usernum; cin >> usernum; const int size = usernum; int myarray[size];
it seems if use variable in way initialize constant size, vc++ no longer sees constant purposes of setting array size.
is there way around this?
this can done usign std::vector
#include <iostream> #include <vector> int main() { int usernum; std::cin >> usernum; std::vector<int> myarray(usernum); myarray[1]=42; return 0; }
note example has no checks size user has entered.
Comments
Post a Comment