-6

I love the site, but why is Stack Overflow so clunky when pasting C++ code?

Is there something I'm missing? What if I have a really long program, that seems rather redundant and annoying to do every time I paste C++ code.

For instance, I paste my code (after indenting four spaces)... (I had to post a picture of it, because Stack Overflow won't let me post unformatted code.)

...And it looks like that.

3
  • 7
    I usually indent the code in my editor already and paste it without problems. If you lose the indentation that might be due to your browser... May 15, 2014 at 17:05
  • 13
    You shouldn't be posting a "really long program". You should be posting a minimal compilable example.
    – nobody
    May 15, 2014 at 17:05
  • 4
    Are you first indenting and then pasting your code? If so, this probably counts as a duplicate of the linked post. May 15, 2014 at 17:09

2 Answers 2

7

The easiest way is to just paste the code. Then highlight it with your mouse and hit Ctrl + K.

0
4

The easiest way in my opinion and what I usually do would be taking care of the indentation in your editor already. For example with gedit (just the editor I happen to use on this netbook for easy tasks.) I do:

  • Ctrl+A to select all the text
  • Tab to indent it all
  • Ctrl+A to select all the text again (otherwise gedit won't pick up the new indentation for the first line...)
  • Ctrl+C to copy it.

Now you just gotta paste it into your question and it is properly formatted. I find this way faster than switching to the mouse.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .