How to remove spaces between lines?

Hi, I hope you have a good day :)
I was wondering if removing spaces between lines is possible, lets say I have this code:

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

int main()
{

std::cout<<"Hello\n";
std::cout<<"World!";

std::cin.get();
return 0;
}


And as expected I'll have automatically spaces between my lines, I don't want that space, is there any way to change/ remove this space?

Thanks!
Last edited on
I have no idea what you're trying to describe/ask. Any chance of rewording that?
I adhere to kbw's request.
You added a new line character "\n" after the word "Hello". Change the new line character to a space and you will be fine.
Ok, sorry for not being clear enough, here is what I want, I want to print multiple lines with no space between them.

Currently, this is what I get if I run the code:
https://drive.google.com/file/d/1WcHpO-qdHWeEdcoPoVh8Eo2LgUwYBBHQ/view?usp=sharing

But with some magic, I want something that looks like this:
https://drive.google.com/file/d/1iWdAv2yj7p5ytcJZdpopDR1uYdKONpSq/view?usp=sharing

I hope I'm clear enough, thanks for commenting :)
The standard output is a stream device. All you can send to it is a series of bytes. What happens to those bytes after you send them to stdout depends on the execution context and is outside the control of your program. They could get sent to a graphical console for display, or to a file, or they could go to a printer to get printed onto paper and then immediately shredded.

In your particular case, your console is displaying the output on a fixed grid. That grid is determined by the console emulator based on the configured font. Maybe this can be configured or maybe it can't, it depends on how the emulator was programmed, but either way it's not something you can deal with from the code. And even if you configure your console to display the text exactly the way you want, if I take your program and run it on my computer the output will look entirely different (although the text will be the same).

If you need tighter control of the display then you need to write a graphical application, not a console application. The console is intended to quickly get information out, without regard for how it looks. With graphics you can display whatever you want, because you're sending pixels to the screen, not characters to a stream device. However, you'll also need to deal with all the complexity that drawing to the screen involves. Text rendering, most importantly.
Last edited on
Yes you'll really need some magic, perhaps you should investigate a graphical interface since the standard console is probably not going to be suitable.

Ok guys, thanks so much for replying! I'll consider developing a graphical application so I have more control about anything, I guess it's time to come back to my OpenGL game idea if we're already talking about it ;)

Thanks again!
I hope I'm clear enough, thanks for commenting :)

I can't see a difference between the two links you posted.

To reiterate what doug4 said, the reason there's a newline in the output is because YOU put it there. In std::cout<<"Hello\n"; that \n is a newline. If you don't want it, then remove it.
dhayden: The difference is the distance in pixels between the words.
Odglog, you also don't necessarily need to use OpenGL for text rendering, although it's certainly an option. If you just want some text box, you can use a GUI library.
Topic archived. No new replies allowed.