I am trying to use VS Code on Mac to run C code. I've used XCode before with no issue but am running into errors while trying to run this code. I am using the Microsoft C and CodeRunner extensions
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main () {
vector<string> names = {"Dan", "Sam", "Man"};
vector<string> *name_ptr = &names;
cout << (*name_ptr).at(0);
return 0;
}
I used Command Shift P to edit the Microsoft C/C Extension configurations and changed the C standard to "C 11." Doing this removed the error squiggles from the vector list but when I ran the code I still received the error:
"error: non-aggregate type 'vectorstd::__1::string' (aka 'vector<basic_string >') cannot be initialized with an initializer list"
I've tried using the advice from Error: non-aggregate type 'vector<int>' cannot be initialized with an initializer list but I am unsure how to pass the "g -std=c 11 myfile.cpp" argument to the compiler. I've tried putting that argument under compiler arguments in the C/C Extension configurations settings to no avail. I am not too familiar with how compilers so I am stuck here.
CodePudding user response:
The Extension configurations are just used to control how the vscode will check your code, but it will not control the real compiling.
The CodeRunner has code-runner.executorMap in which you can set the argument.
p.s. I used to be puzzled by configuring the arguments and abandon. Now I just use a terminator to directly run the command. Maybe it will save time on handling a lot of configs that I will never use.
CodePudding user response:
I can't work with something such as vector, set, map, string... like you. I can not run my code on VSCODE if i use them, but in DevC, my code run normaly. T don't know how to handle with this problem T.T
