Text doesnt wrap round

Sep 12, 2009 at 8:22pm
Well basically when I cout << to the terminal (mac equivelant of cmd), the text doesnt wrap around and so I was wondering how I can solve this? Is the only way putting strategically placed whitespaces?
Sep 12, 2009 at 8:39pm
Try this:


cout << "Text that you want displayed" << endl;

That should make it go to the next line.
Sep 12, 2009 at 9:37pm
I don't know what you mean by "wrap around".
Don't use endl. It draws a newline and flushes the buffer. Use \n at the end of your string instead:
std::cout << "Some text and a newline\nThis is a different line\n";
Then if you need to flush the output buffer:
std::cout << std::flush;
If you need to draw a newline and flush the output buffer,
std::cout << std::endl;
Which is approximately equal to
std::cout << "\n" << std::flush;.

By the way, the terminal is what the shell is called on all UNIX systems, pretty much. It's still a terminal on windows, they just call it "Command prompt", and the less informed people call it DOS. Even though it has nothing to do with DOS; just similar commands.
Sep 13, 2009 at 12:05am
I wouldn't say less informed. I know it's not DOS.. at least not anymore. It's just a throwback from old days that I still habitually use. It's a habit that's about as hard to break as smoking was.

I sometimes call the terminal in Linux the DOS window too. Which is very similar to calling diesel fuel, gas. It's incorrect, but as long as you know not to actually put gasoline into the fuel tank, you won't blow up the engine.
Sep 13, 2009 at 2:12am
In response to the original question... not all terminals wrap text. Many, in fact, have options that you can set to cause it to either wrap or truncate text. Make sure that you output newlines at appropriate spots and don't rely on the terminal being set-up to do the right thing.

Hope this helps.
Sep 13, 2009 at 4:52pm
Ah ok thanks everyone.
Topic archived. No new replies allowed.