25

I'm having a problem with the C++ extension of VScode. Whenever I define a matrix consisting of vectors like vector<vector<int> > and use the auto formatter, it changes the code to vector<vector<int>> which results in a compiler error.

Is there any solution to this?

Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
manuelgr
  • 498
  • 1
  • 8
  • 26
  • 26
    That sounds like you are using a really old compiler version where that parsing issue is not resolved by the language yet... Is upgrading to a newer compiler an option? – Max Langhof Oct 22 '18 at 11:46
  • 14
    You'd be hard-pressed to find a compiler that doesn't support this in C++11 mode. @Erebos Try adding `-std=c++11` to the compiler flags. – rubenvb Oct 22 '18 at 11:53

2 Answers2

42

The VSCode C++ extension uses clang-format for formatting the document. If you are stuck with an old compiler which doesn't support C++11, just add a .clang-format file in your workspace with following line:

Standard : Cpp03

For more formatting options, refer to the following link: https://clang.llvm.org/docs/ClangFormatStyleOptions.html

Boann
  • 48,794
  • 16
  • 117
  • 146
Nishant Singh
  • 4,177
  • 1
  • 17
  • 17
28

The compiler error is that >> is interpreted as the right shift operator instead of two consecutive template argument list delimiters. Before C++11 this was how the language required the parser to work. However, in C++11, an exception was added to prevent this. See this answer for more information.

The best solution would be to upgrade your compiler to C++11 or later.

Max Langhof
  • 23,383
  • 5
  • 39
  • 72