Visual Studios 2013 indenting code - c++

It's not necessary I fix this 'issue' since it's a more aesthetic thing. I was just wondering if it's possible to indent code that comes under the "public:" deceleration after indenting the deceleration itself.
So it would look like this:
class Myclass{
public:
void test(){
}
}
At the moment the void part would be directly underneath the public modifier. I have looked through the formatting setting and yet cannot find how to do this.

In visual studio open Tools/Options. In the menu on the left choose Text Editor->C/C++->Formatting. There you can change a lot of things like indentation.

Related

visual studio intellisense for c++

I am using visual studio and In the following c++ code
using namespace std;
void f() {
}
int main()
{
// using ctrl + space
cin.get();
return 0;
}
When I use Intellisense suggestions in main function it does suggest f function but when I click on it or press tab it just writes f not f().
Is there anyway to correct this and not to add () myself after all function calls?
It is a well-known problem that I have handled it before.
For VS, actually, it could not be done automatically now and VS does not have this Intellisense feature by default.
As a suggestion, before you click Enter to complete automatic filling from the Intellisense suggestion window, press the key combination Shift + ( and it will automatically add () with the method.
Or just Use Resharper Extension and this extension has the feature for automatically adding brackets to methods.
Besides, this DC ticket has raised this idea to the Team. You could vote it and more votes will help the Team pay more attention to this and add this feature to VS IDE as soon as possible.
Resharper is the extension that does just that
https://www.jetbrains.com/resharper-cpp/

Modify default C++ snippets in VS Code

I would like to modify the default code snippets for C++ in Visual Studio Code. I've found a similar question here, but they actually show how to create your own snippets - and not how to modify the default snippets.
The reason I want to do this is because I'm used to doing some things a bit differently than how they are done in the snippets. For example, this is what appears when I use the if snippet:
if (/* condition */)
{
/* code */
}
And I would like it to be like this:
if(/* condition */){
/* code */
}
Is there any way to achieve what I want to do? Thank you.
Press Ctrl + ,(opens vs code settings);
Type "snippet" in settings search bar;
In Extentions List choose C/C++
Untick "Suggest Snippets" button;
Close settings tab.
Go to settings again and create new User Snippets 😊as you liked.enter image description here

Visual Studio 2019 - don't insert a linebreak when opening curly braces (C++)

I want to declare a variable like this:
int foo {5};
But as soon as I open the first curly brace, VS does this instead
int foo {
}
I've spent a long time trying to find the relevant option but haven't had any luck.
Thanks.
Click "Options" in the upper toolbar, go to "text editor" in the left menu in the appeared window, choose "C++", "Formatting" and order Visual Studio to never newline such statements.
I couldn't reproduce the issue at vs2019. I suggest you could try to reset settings.
Tools->Import and Export Settings...->Reset all Settings->Next->"No, just reset settings, overwriting my current settings"->Next->General->Finish

Header guard deactivates IntelliSense within it

Well, let's say I have simple code like that:
#ifndef SYSTEM_CLASS_H
#define SYSTEM_CLASS_H
class SystemClass {
public:
SystemClass();
bool Initialize();
}
#endif
My issue is that everything within the header guard is ommited by IntelliSense. Is it intentional? Is there any way to disable it? I tried to look for solution on SO and Google, but I found nothing. I'm using VS 2012 Express, which recently got 3rd update.

Creating a simple VS2008 visualizer inside autoexp.dat (problem with casting)

I have a large project of mixed C/C++. I've created a simple visualizer for the ICU UnicodeString class as follows...
[inside autoexp.dat]
icu_4_2::UnicodeString {
preview ([$c.fUnion.fFields.fArray,su])
}
...and that works fine. Inside the debugger wherever I see the object I now see the text inside in the preview line.
I then created a wrapper class containing one of these objects as follows...
class StringHandleData
{
public:
icu_4_2::UnicodeString str;
};
...and then created another visualizer for this...
[inside autoexp.dat]
StringHandleData {
preview ([$c.str.fUnion.fFields.fArray,su])
}
...which again, works fine. Whenever I see a StringHandleData object in the debugger I see the text inside in the string.
However, my problem comes when I define a typedef I can use inside C code like this...
typedef void* StringHandle;
...which under the hood is actually just a ptr to a StringHandleData object. So when I try and create a visualizer for the StringHandle type like this...
[inside autoexp.dat]
StringHandle {
preview ([((StringHandleData)$c).str.fUnion.fFields.fArray,su])
}
...it doesn't work. I've tried lots of other ways of casting the object too but with no luck so far. If I go to my watch window and cast a StringHandle like this... (StringHandleData*)stringHandle then the debugger makes the cast and previews correctly - but I just can't seem to get it to do it automatically from inside autoexp.dat
Thanks for any help.
Visual studio's visualiser is blind to typedefs and will think StringHandle is a void *.