0

I tried a lot of different ways, but the only way is manual.

I tried with Ctrl + K and inserted the code, but it's badly rendered, and a lot of text is not inserted into the code.

Is there some solution for this?

closed as unclear what you're asking by curiousdannii, Glorfindel, Robert Longson, gnat, PolyGeo May 20 '18 at 21:58

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Here's some more information on how to avoid some obstacles with posting code. But apparently didn't work for the OP at Stack Overflow specifically. – πάντα ῥεῖ Apr 25 '18 at 17:39
  • 3
    @πάνταῥεῖ: Well, there are quite a number of sites that rely on putting substantial chunks of code in the question (Code Review, SO, sometimes Software Engineering or Unix&Linux or Tex, etc). – Nathan Tuggy Apr 25 '18 at 18:02
  • @NathanTuggy Yeah, you're probably right. The question needs more clarification about the specific problems though. "and lot of text is not inserted into the code" We need a reproducible example. – πάντα ῥεῖ Apr 25 '18 at 18:16
  • Copy and paste. Faster than typing manually. Each OS has its own way to copy and paste things, e.g. in Windows it's CTRL+C for copy, and CTRL+V for pasting. – Shadow The Dragon Wizard Apr 25 '18 at 18:34
  • 1
    It's unclear what you are asking. Did you not know about copy pasting text, as Shadow Wizard illustrated? Or do you actually really use ctrl-k before pasting the code, in which case you need to paste the code, select it, and only then format the code? Formatting code definitely works. – Félix Gagnon-Grenier Apr 25 '18 at 19:04
  • 2
    @Felix "Or do you actually really use ctrl-k before pasting the code" I tried to address that misconception in my answer. – πάντα ῥεῖ Apr 25 '18 at 19:39
  • Yes, thanks for that @πάνταῥεῖ :) let's see what time says now! – Félix Gagnon-Grenier Apr 25 '18 at 19:41
4

I am just used to

  1. Copy my code from my currently used IDE or text editor: Enter image description here
  2. Paste it into the editor window Enter image description here
  3. (Select it when needed) and press Ctrl + K Enter image description here

Here's an example of the result:

#include <iostream>

int main() {
    std::cout << "Hello World!" << std::endl;
    if(true) {
        DoSomething();
    }
}

You can inspect my example results above by clicking the edit button below.

I tried with ctrl-k and inserting the code, ...

Be sure to do it in the order mentioned in the above steps.


There's a maximum number of characters you can post in a single question though. Refer here to see the details please:

Anyway, at Stack Overflow (and some other sites) you should try to shape your code well, to fit within the rules of a MCVE (emphasis on minimal).

On the contrary, - at SE Code Review for example -, it is allowed to post even lengthy and complete code, but maybe better split up into a sequence of related questions, if it doesn't fit into a single question (or answer) post.

  • yeah but when the code is very long like i said before.. lot of text is not inserted into the code – Sergio Ramos Apr 25 '18 at 18:51
  • 1
    @SergioRamo There's an overall limit of characters you can use in your post. And if your code is very long, you should notice that you're supposed to post a [MCVE] (emphasis is minimal in this context) at Stack Overflow. – πάντα ῥεῖ Apr 25 '18 at 18:57
2

I just paste my code into a text editor, select all, double tab, copy all, and paste it into the question / answer block.

  • 2
    What if your code originally contains tab characters? You probably want to clean these up (convert to blanks) before inserting it into the post. Otherwise you'll be thrown with some unreadable mess. Also the difference between editor window and preview isn't easy to spot and clear for such cases. (Notepad++ is your friend) – πάντα ῥεῖ Apr 25 '18 at 17:41
  • @πανταρει good points. Given that most of the code (terminal output) that I edit in doesn't have tabs, that didn't occur to me. – anonymous2 Apr 25 '18 at 17:47
  • It often depends on IDE settings. Especially Visual Studio wen't with the dark side of the schwitz, and defaults to use TABS not being auto converted to blanks. On the other hand with e.g. GNU make files, TAB characters are an essential need . Anyways, in the end markup doesn't render them correctly, and need some adjustment to keep your code readable at SE sites. Not to mention that you don't need that extra step to paste in the editor. CTRL-K just works fine (unless there's a problem like I've pointed out above). – πάντα ῥεῖ Apr 25 '18 at 17:54
  • Hmmm, I just was about writing my own answer, and tested what I've mentioned about the TAB characters. They seem to render just well now (I had a different experience times ago). There seem to be some other problems the OP encountered when using CTRL-K. The question needs to be more clarified what's there actual problem. – πάντα ῥεῖ Apr 25 '18 at 18:10

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