manuelgr
manuelgr

Reputation: 518

Auto formatter changes > > to >>

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?

Upvotes: 25

Views: 2673

Answers (2)

Nishant Singh
Nishant Singh

Reputation: 4855

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

Upvotes: 42

Max Langhof
Max Langhof

Reputation: 23681

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.

Upvotes: 28

Related Questions