Indenting function braces in Eclipse - c++

I am working on a C++ project and using Eclipse as the IDE. The coding standards for the project specify indenting the initial and closing braces for a function, as in:
int main()
{
return 0;
}
Is there an option in Eclipse 4.3.1 to automatically indent this way?

Use the main menu to Navigate to Window->Preferences.
On the resulting dialog, expand your way to C/C++->Code Style->Formatter. Set Active Profile to Whitesmiths and edit to taste.
For example, it looks like you want to set Indentation size and Tab size on the Indentation tab to 2.

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/

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

How to fix visual studio autocomplete when typing for loops?

This has been really bugging me ever since I switched from VS 2015 to VS 2017.
Here's what's happening:
When I type this
for(int i = 0; i<v.size()
then add a semicolon, VS autocompletes the line to this:
for(int i = 0; i<v.size());
This is clearly not what I want, since I still need to type the increment portion of the for loop.
How do I prevent autocomplete for this specifically?
It is strange that you are typing this manually. Have you tried using stock code snippets? Type for and you should get a popup with for snippet selected -> press Tab to insert body and autoselect index variable type -> type new type -> press Tab to select index variable name and so on; finally press Enter to jump into loop body.
It's a bug that was introduced in VS2017. Make sure to bump the thread dedicated to this issue, and hopefully this will encourage the VS team to prioritize fixing this bug in a future release.

How to stop Clion tab key behaviour

When on a C++ line of code like the following
aType.aMethod(
std::make_shared< T_1>();
^^^^^-- Press tab here
)
Clion tries to move to the next parameter(i guess), but being the only parameter it goes nowhere. I want to have the tab to just insert characters(tab or space that is) and not to try to cycle the cursor among the method parameter. Is there a way to stop this alternative functionality?
I searched to no avail in
Settings|Editor|CodeStyle|C/C++
Thank you
"Try changing the "Next parameter" and "Previous parameter" keybindings to something else than Tab."
– Eldar Abusalimov Jul 5 '17 at 9:02
In addition to the accepted answer, i found that tab was assigned to Next Live Template Parameter Under : Main Menu | Navigate | Navigate in File (This is in the keymap section in settings, not the actual main menu). So when i generated definitions for the methods in my class and it jumped into the cpp if there were any auto generated functions with return initializer; as the method body it would jump to these instead of letting me indent code so i turned that off too and now i can happily implement the methods in order and fix those up when i get to them. Alternatively if you like that setting and want to keep it turned on, Hopefully knowing that you have to tidy up all instances of return initializer; before the tab key will indent code again is useful to you, i found it very confusing.
EDIT: i realise this wasn't part of the original question, but this is where googles top result brought me, so i hope you don't mind me adding this info here as its still related to the tab key doing weird things in CLion.

Eclipse C++ formatting

Is there a way to make eclipse format stuff like this:
int x;
bool hasX;
MyClass longName;
into:
int x;
bool hasX;
MyClass longName;
I think I once did it in Java Eclipse, but I can't seem to find it in the eclipse c++ format options.
Edit:
I don't have such option in my formatter
In the preference--> C++-->Code Style-->Formatter
Click the "Edit" button, in the "Indentation" tab, check the "Use spaces to indent wrapped lines".
Once this is done, pressing "Ctrl+Shift+F" in the editor will automatically align the text the way you have asked.
Hope this helps:)