Mac bookを使用しているのですが、Visual Studio Codeの拡張機能Code Runnerで、
以下のようなvectorを使用したC++ファイルを実行するとエラーメッセージが出ます。
vectorを使用するには何を修正したらいいのでしょうか。
c++
1#include <bits/stdc++.h> 2using namespace std; 3 4int main(){ 5 vector<string> s = {"a","bb","ccc","dddd"}; 6 cout << s.at(0) << endl; 7 8 vector<int> i = {1,2,3,4}; 9 cout << i.at(1) << endl; 10}
エラーメッセージ
teratail.cpp:5:20: error: non-aggregate type 'vector<std::__1::string>' (aka 'vector<basic_string<char> >') cannot be initialized with an initializer list vector<string> s = {"a","bb","ccc","dddd"}; ^ ~~~~~~~~~~~~~~~~~~~~~~~ teratail.cpp:8:17: error: non-aggregate type 'vector<int>' cannot be initialized with an initializer list vector<int> i = {1,2,3,4}; ^ ~~~~~~~~~ 2 errors generated.
使用コンパイラやc++の規格等k_motoさんの環境を
質問に追記していただけませんか。
回答1件
あなたの回答
tips
プレビュー