I cannot define a string array for unknown reasons on C++. I need to randomly get a string from this array.
Been trying the following:
string bands[] = { "Rammstein", "Slipknot", "Franz Ferdinand", "Gorillaz" };
I’m getting the following as error:
error C2146: syntax error : missing ';' before identifier 'bands'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C3845: 'SpurdoSparde::Form1::bands': only static data members can be initialized inside a ref class or value type
Just a reminder, I’m using a Windows forms applications. Not sure if it makes any difference whatsoever.
It seems you are not including
stringand/or notusing std::string. The following works:If you are after a dynamically sized collection of strings, you should prefer
std::vector<std::string>over a C-style array. If you need fixed size, have a look atstd::array<std::string, N>ortr1orboostalternatives if you don’t have C++11.