VS code indentation when copying and pasting is messed up - indentation

Why is the indentation almost always messed up when copying and pasting code in VScode?
For example:
Copying:
Pasting:
Another example:
And it's sometimes even more messed up.
Is there a way to fix it?

I'm new to VSCode, but do you have "editor.formatOnPaste": true?

Related

Why is Clion giving me an error when I declare a struct inside a function?

The application compiles without any issues, however Clion says that my code has an error. What could be the reason? If I move the declaration outside the function, it doesn't give me any errors.
Maybe it's because I come from a time where intellisense was so unreliable, frequently failing to update and act on the new code I just wrote, or frequently crashing completely, or messing its cache or sowing errors on the word I was just typing, or not being updated with the new implemented feature in the compiler or etc. etc., but I am being constantly baffled by people freezing and panicking when the intellisense shows a false positive or just goes nuts when in fact there is nothing wrong.
Don't rely so much on your IDE realtime error checking! The compiler is the one that compiles your code. The compiler is the only one that matters!
The rest are just tools to help you code. If they fail you are still expected to be able to write code.

C++ in Netbeans: many senseless "unexpected token" hints

I am very new to coding C++ and to using the Netbeans IDE. Worse yet, I'm on a Mac (but I can't imagine that's the source of the issue this time).
The IDE is giving me countless nonsense "hints" as in red exclamation mark symbols, most of which say "Unexpected token" for things like ';' at the end of a statement or '=' in a statement. These are of course ridiculous because, as I understand c++ so far, they are necessary for even the most basic statements!
screenshot here
What could possibly be causing this and how do I get rid of the hints or, preferably, fix something if there is an error somewhere?
Delete your Netbeans cache. In my case the problem when away when I did this. I think I initially ended up in this state because my C++ project was under a Java project. After separating the two the error was still present even with a clean/build. Deleting the Netbeans cache got rid of the problem. Even if your situation is different you should try this. Clearing the Netbeans cache once in a while fixes a lot of issues.
Tyler,
I'm going to go out on a limb and guess that you've got your Net beans ide setup to use another language other than C++. Remake the project and make sure your using c++
I had the same issue.
The issue was, I wrote C++14 code, in the C++ project.
To resolve this:
- Create a C++14 project (Select from the drop down, while creating the project)
- Add existing C++ files to it
Hope that helps.

How to make clang-format keep closing braces on same line

Basically the indent style I'd like to obtain is the one described as 'Lisp style' on Wikipedia:
while (x == y) {
something();
somethingelse(); }
I'm using a custom .clang-format file (version 3.8) but I couldn't find any option suited for my need.
Thanks in advance.
The clang-format source code is pretty clean, it's not too difficult to read it or modify it once you get the idea.
Here's a patch I made like a year ago that adds a "break before brace after constructor initialization lists", in clang 3.7. (It didn't get merged after discussion unfortunately, but I kept using it for my own projects anyways.) It's not too much code: https://github.com/cbeck88/clang/commit/e4f65cf7ab3deea9e6c7cdd5900ad0362835e514
Figuring out how to build clang and run the clang unit tests is probably as much work as actually making a patch to do what you are saying.
As I recall, the source code is more based around adding breaks rather than removing them, so depending on exactly how you want to formalize your idea (is this only control structures? For if's? For brace ending a function or class?) it might be tricky. But I still expect you would be able to get it to work.
To my recollection, there are no built-in options to do something close to what you are saying.

Corrupt Builds with Visual Studio

Recently i have been experiencing more and more corrupt builds.
For instance when i access
npc[4]
it accesses
npc[3].
Or instead of
details->Hp
it returns
details->Energy.
Problem magically fixes itself when i rebuild. (after i spent hours trying to find the non-existing bug of course)
This is getting more frequent while my project gets bigger and bigger.
Why does something like this occurs?
How can i avoid it?
I hope i made myself clear.
thank you.
thanks for the comments. i have found the problem.
precompiled headers. they get corrupted after a while and cause unintended behaviors.
there doesn't seem to me solution at the moment since I'm forced to use pchs.

Namespace loop or code leak in boost::function?

I'm really baffled by this. Have I managed to do something to cause this, or is it an unclosed namespace block in boost, or some bug in VS c++ 2008? I'm definitely sure I've closed all my own namespaces properly, all includes are outside of and above them, and all my header files got include guards.
alt text http://lowtown.se/stuffs/superboost.png
The boost/function.hpp is only included in this header. Two other headers in my library includes the boost/cstdint.hpp but they don't have this problem.
Visual C++'s intellisense is a bit quirky. Sometimes it screws up. That doesn't mean there is a problem in your code. Always take C++ intellisense with a grain of salt.
Sometimes intellisense does that. If you use Visual Assist X it will fix that, but it is a very expensive program :(
Usually deleting ncb-file solves most of Intellisense problems. If it doesn't help — buy VA.