我無法在C++中爲未知原因定義字符串數組。我需要從這個數組中隨機獲取一個字符串。數組中的隨機字符串
一直在努力執行以下操作:
string bands[] = { "Rammstein", "Slipknot", "Franz Ferdinand", "Gorillaz" };
我收到以下錯誤爲:
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
只是一個提醒,我使用的是Windows窗體應用程序。不知道它是否有任何區別。
你忘了'的std ::'或'包括'? –
Rapptz
與您的問題無關:您應該使用'std :: vector'而不是'[]'數組。 – us2012
確保你有'#include'和前綴'std ::'的字符串,如'std :: string bands []] = {...}' –
dchhetri