官术网_书友最值得收藏!

Formatting your code (Autocomplete settings) in Visual Studio

Code-writing formatting with Visual Studio is a pleasure. In this recipe, we'll discuss how to control the way Visual Studio lays out the text of your code.

Getting ready

Code has to be formatted correctly. You and your co-programmers will be able to better understand, grok, and keep your code bug-free if it is consistently formatted. This is why Visual Studio includes a number of auto-formatting tools inside the editor.

How to do it...

  1. Go to Tools | Options | Text Editor | C/C++. This dialog displays a window that allows you to toggle Automatic brace completion.

    Automatic brace completion is the feature where, when you type { , a corresponding } is automatically typed for you. This feature may irk you if you don't like the text editor inserting characters for you unexpectedly.

    You generally want Auto list members on, as that displays a nice dialog with the complete names of data members listed for you as soon as you start typing. This makes it easy to remember variable names, so you don't have to memorize them:

    Tip

    If you press Ctrl + Spacebar inside the code editor at any time, the auto list pops up.

  2. Some more autocomplete behavior options are located under Text Editor | C/C++ | Formatting:

Autoformat section: Highlight a section of text and select Edit | Advanced | Format Selection (Ctrl + K, Ctrl + F).

How it works...

The default autocomplete and autoformat behaviors may irk you. You need to converse with your team on how you want your code formatted (spaces or tab indents, size of indent, and so on), and then configure your Visual Studio settings accordingly.

主站蜘蛛池模板: 太原市| 松潘县| 望江县| 格尔木市| 肥乡县| 德江县| 沁阳市| 桃园市| 上林县| 梅州市| 许昌县| 枣强县| 年辖:市辖区| 商洛市| 雷波县| 淮南市| 潢川县| 壶关县| 华宁县| 彭阳县| 昭觉县| 临湘市| 霍林郭勒市| 讷河市| 启东市| 大理市| 格尔木市| 同仁县| 囊谦县| 和田市| 哈巴河县| 灵山县| 平塘县| 扎赉特旗| 德昌县| 普格县| 泰顺县| 延寿县| 西安市| 凌云县| 永安市|