How to remove spaces between lines?

May 21, 2020 at 11:34am
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 May 21, 2020 at 3:22pm
May 21, 2020 at 5:38pm
I have no idea what you're trying to describe/ask. Any chance of rewording that?
May 21, 2020 at 5:44pm
I adhere to kbw's request.
May 21, 2020 at 6:03pm
You added a new line character "\n" after the word "Hello". Change the new line character to a space and you will be fine.
May 21, 2020 at 10:02pm
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 :)
May 21, 2020 at 10:14pm
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 May 21, 2020 at 10:17pm
May 21, 2020 at 10:16pm
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.

May 23, 2020 at 10:35pm
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!
May 23, 2020 at 10:56pm
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.
May 23, 2020 at 11:34pm
dhayden: The difference is the distance in pixels between the words.
May 23, 2020 at 11:57pm
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.