How to stop visual studio 2017 c++ from autocompleting ) while in the middle of FOR statement? - c++

So every time I write something like
for (auto i = 0; i < my_vector.size();
the moment I add the semicolon after a function call in a for statement, it turns into
for (auto i = 0; i < my_vector.size());
and then I have to manually delete the automatic bracket close because I havent finished the for statement, super annoying.
I don't remember earlier VS versions doing this.
Anyway I tried going in options -> text editor -> c/c++ -> formatting -> general, I tried switching off "Automatically format statement when I type a ;" and also "Automatically format braces when they are automatically completed". Both had some minor effect but the problem I described was still happening.
I like autocomplete most of the time, I find it useful so I don't want to turn it off completely but how can I make it stop doing that one thing?

Update the Visual Studio. That particular (VS 2017) bug is now fixed starting with the VS 2017 15.4 Preview 2 update.

Related

How to change a variable value on conditional breakpoint in visual studio 2015

Is there any way to change value of variable to on a conditional breakpoint and continue execution.
My code is like this
switch(var){ //conditional breakpoint on this line
case 1:
break;
...
}
I put conditional breakpoint like below
(var == 0 ) || (var ==1) is true
So when this breakpoint hits, I want to change var = 2, and continue execution.
What I found: I found Action also, but it only log messages. Is there any way to executing a statement like var = 2 as Action taken on this conditional breakpoint.
I don't want to change code because building it takes hell lot of time.
Note: I am working C++ on Visual studio 2015
In Log a message to Output Window write {my_variable=12345} the side effect of log output is assigning 12345 to my_variable.
Take into account that Log a message can accept and evaluate complex expressions in curly braces.
You can modify a variable directly in memory to change the execution flow through a quick watch (Shift+F9) or watch window in Visual Studio.
Make sure that in Tools / Options / Debugging you have the "Enable Edit and Continue" Enabled/Checked and then you will be able to edit your code while debugging and continue without the need to rebuild or to stop execution.
More information can be found in How to: Enable and Disable Edit and Continue
This used to work, I can't seem to get it to work now. Worked excellent on loops and also good for altering values without altering the source or the code (and accidently committing it).
Conditional break point, break if true
(url = "http://localhost:1234/") != url
This works thanks to assignment always returns it's assigned value. This will never be true as url becomes localhost

Visual Studio 2013 C++ auto indenting doesn't work well

For some reason, after I type the following block in Visual Studio 2013:
for (int i = 0; i < m; i++)
if (some_condition)
{
}
VS 2013 automatically indents the code to this:
for (int i = 0; i < m; i++)
if (some_condition)
{
}
If I put the if between curly brackets, it formats the code correctly. This behavior is very frustrating. I don't remember having this issue in VS 2012.
If I disable auto formatting, it doesn't even put the cursor at the same indent level as the line above. Even notepad++ works better than VS.
Is there a way to fix this? Maybe to import the indenting rules from VS2012 which worked just fine?
Bug is fixed with VS 2013 Update 1. Try install it Tools -> Extensions and Updates -> Updates -> Product Updates -> Update 1
Can you change settings as below and check
In Tool->Options->Text editor->C/C++->Format-> Indentation (un-check this option)
and reformate code block once or try new code.

VARIANT members not resolved in C++ OLE automation application (Eclipse IDE)

I'm developing a C++ application that reads and writes to Excel using OLE automation (code based on this: http://support.microsoft.com/kb/216686).
The application has been up and running just fine when I was using VS2010. However recently I decided to move to Eclipse, and all of a sudden the compiler (CL) won't recognize the structure of the VARIANT struct (doc: http://msdn.microsoft.com/en-us/library/aa908601.aspx). For instance in this piece of code:
VARIANT tmp;
tmp.vt = VT_R4;
tmp.fltVal = 5.0f;
tmp.fltVal cannot be resolved in Eclipse (while it works just fine in VS2010, and every code sample I've seen online). The only way to get Eclipse to stop displaying an error is to replace the last two lines with:
tmp.n1.n2.vt = VT_R4;
tmp.n1.n2.n3.fltVal = 5.0f;
Same goes for tmp.parray and all other members of VARIANT.
Has anyone come across this before ? What am I missing here ?
PS: No, replacing the code everywhere is not exactly an option

Visual Studio Auto Format Curly Brace on Next Line

I am so used to code like this:
if (...)
{
//somecode
}
that I simply have to change the following to the above:
if (...){
//somecode
}
I get a lot of code from other people that I have to go through and sometimes this is what I get. Is it possible to auto-format that in Visual Studio 2008 for C++?
Now some may think I should get used to it. Believe me, I am trying, but it is very distracting and I hope there is a simple solution.
VS2008 has a simple formatter (Edit menu, Advanced, Format Selection), but it doesn't move braces.
Check out astyle and its --style=ansi flag.

Indention in C++ Builder

In C++ Builder, how can I make sure that even correctly nested code like:
void func () {
...
..
)
C++ Builder correctly nested only doing so:
void func ()
{
...
...
}
This is very stressful, because I always have to correct by hand. So how can I make which indents code as well in the first instance?
The code formatter in C++Builder 2010 should do this automatically for you. (It is invoked with CTRL-D) You’ll have to set the preferences to how you like your code to be formatted, but this is a real time saver new with this most recent release.
Select the block, then press CTRL+SHIFT+I. This is in Borland C++ 6.
I am using this free tools:
http://www.cnpack.org/index.php?lang=en
using tabs to shift marked blocks to left or right.
I don't have a copy of this to run, but the documentation mentions "Indentation, Spaces, and Line breaks" as some of the options under the formatter tab of the "Tools > Options" dialog.
What you're looking for is probably under the "Line Breaks" section.