In Visual Studio 2022 how to automatically use codestyle with spaces before and after * and &?

Cristian Laczko 0 Reputation points
2023-10-09T19:55:12.23+00:00

In the code base I work these are the rules for & and * operators: spaces before and after.

int findComboBoxItemByInternalName(QComboBox * comboBox, const std::string & targetInternalName)

I found no option in Options->Text Editor->C#->Code Style->Formatting->Spacing that can influence that. And the code style is enforced to:

int findComboBoxItemByInternalName(QComboBox* comboBox, const std::string& targetInternalName)

Developer technologies Visual Studio Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tianyu Sun-MSFT 34,436 Reputation points Microsoft External Staff
    2023-10-10T05:05:14.7533333+00:00

    Hello @Cristian Laczko ,

    Welcome to Microsoft Q&A forum.

    Not 100% sure, as you shared only code snippets without information about the project type(I guess it’s Qt project?). But, are you sure it’s C# code? Looks like it’s C++ code.

    I tested in a newly created simple C++ project, with default VS settings, and the operators shows correctly(align center).

    Please check following options:

    Tools => Options => Text Editor => C/C++ => Code Style => Formatting => Spacing => Spacing for operators => Binary operators => Insert spaces before and after binary operators.

    Tools => Options => Text Editor => C/C++ => Code Style => Formatting => Spacing => Spacing for operators => Pointer/reference alignment => Align center.

    Best Regards,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.