winforms - Why is input from a numericUpDown object not considered constant? -
i making basic gui password creator creates random sequence of letters, numbers, , symbols in c++ (it's windows forms application). using numericupdown object retrieve user input length of password being created. trying define char array using number length, error says "expected constant expression." tried defining constant variable doesn't work. there workaround?
the below code part of executed when "randomize" button pressed (the button prompts password created , displayed.
const int length = system::convert::toint16(numericupdown1->value);
and later in program:
char p[length];
you cannot declare arrays variable size in c++ (same goes c++/cli).
it sounds want generate random array of characters , convert system::string
(system::string
immutable, need array manipulate data). this, you'll want use array<wchar_t>
instead.
array<wchar_t>^ data = gcnew array<wchar_t>(system::convert::toint32(numericupdown1->value)); // fill each character in data random character. system::string^ password = gcnew system::string(data);
edit: in case you're wondering why wchar_t
instead of char
: in c++/cli, wchar_t
analogous system::char
, character type used .net. char
analogous system::sbyte
(a signed byte).
Comments
Post a Comment