I'm having a problem with vector initialization.
When I try to run this code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
const int SIZE = 3;
vector<int> a{5, 5, 5} ;
cout << "a contains ";
for (int i = 0; i < SIZE; i++)
cout << a.at(i) << ' ';
cout << '\n';
for (int i = 0; i < SIZE; i++)
a.at(i) = 8;
cout << "a contains ";
for (int i = 0; i < SIZE; i++)
cout << a.at(i) << ' ';
cout << '\n';
}
I keep getting this error:
tempCodeRunnerFile.cpp:8:18: error: expected ';' at end of declaration
vector<int> a{5, 5, 5} ;
^
;
1 error generated.
I'm trying to figure out to run c++11 or c++14 but I'm lost at the moment.
My c_cpp_properties.json file:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}",
"/usr/include/c++/4.2.1",
"/usr/include/c++/4.2.1/tr1"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"macFrameworkPath": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17"
},
{
"name": "Linux",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
},
{
"name": "Win32",
"includePath": [
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include",
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 3
}
My tasks.json file:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "g++",
"args": [
"-o", "test", "-std=c++14", "vectoroutofbounds2.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
I've tried to solve this issue by following ways from github, solution1 and solution2 but still doesn't work.
How can I fix this??
Aucun commentaire:
Enregistrer un commentaire