-6

I just have this simple Hello world program that I would like to run in terminal.

#include <iostream> 
int main() {
    std::cout << "Hello World!";
    return 0;
}

And when I run the output file in the terminal. It prints like this. enter image description here

Is there anyway to have the output come out on a new line instead. So it's more like:

*Hello World!

*new terminal line

Thanks in advance.

  • 3
    `std::cout << "Hello World!\n";` – kebs Aug 24 '21 at 08:17
  • 3
    If you want a new line ... just print a new line? Any [good C++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) will cover this, probably on the first few pages. Or put "C++ print newline" or similar into your favorite search engine. https://idownvotedbecau.se/noresearch/ – Lukas-T Aug 24 '21 at 08:18
  • 2
    You may want to read this: [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/q/285551/12149471) – Andreas Wenzel Aug 24 '21 at 08:20

3 Answers3

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

or

std::cout << "Hello World" << std::endl
Karen Baghdasaryan
  • 2,407
  • 6
  • 24
ojesseus1
  • 43
  • 5
1

That should do it:

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

Andreas Wenzel
  • 22,760
  • 4
  • 24
  • 39
Lukas
  • 110
  • 11
1

There are two options:

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

or

std::cout << "Hello World!" << std::endl;