intmain() { vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg) { cout << word << " "; } cout << endl; }
仔細研究一下錯誤訊息,嗯… 這個案情並不單純啊!
1 2 3 4 5 6 7 8
test2.cpp:9:23: error: expected ';' at end of declaration vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"}; ^ ; test2.cpp:11:29: warning: range-based for loop is a C++11 extension [-Wc++11-extensions] for (const string& word : msg) ^ 1 warning and 1 error generated.