Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format space between operators C++ Visual Studio?

What I am trying to acheive is to find if there exists a way to format the space between the operators in C++, Visual Studio (2012 in my case).

For example writing the following line of code in C#:

int number=10;

Then hitting Ctrl+K,Ctrl+D in C# is formatting the code to:

int number = 10;

As it can be seen there were added spaces between the equal operator (=). When I try to format the code in the same Visual Studio, but for C++, is added indentation only on branches, but the space between operators remains the same.

Is it possible to achieve the same functionality for C++?

Edit

This is what I see in C/C++ > Formatting:

enter image description here

like image 280
meJustAndrew Avatar asked Oct 26 '25 14:10

meJustAndrew


1 Answers

I no longer have VS 2012, but for VS 2013 and 2015 you can do the following (I imagine it hasn't changed a whole lot):

Check Tools > Options... > Text Editor > C/C++ > Formatting > Spacing, and find "Spacing for operators"

There you should have a number of settings, like "insert spaces before and after binary operators"

In your specific case, you'll want to make sure "Insert spaces around assignment operators" is selected.

Afterwards, auto-format should take care of it for you.

Edit: I was able to check a machine that had VS 2012, and indeed there is no option like this (msdn link). Sounds like you need to upgrade if you want this ability.

like image 140
AndyG Avatar answered Oct 28 '25 06:10

AndyG