BaBazinga
BaBazinga

Reputation: 159

Microsoft Visual Studio 2013 C++ --- Press any key to continue on a new line?

Whenever I print something to the screen, the line: "Press any key to continue" shows up right after without a line break. For example if I am printing "Hello World", the cmd will print out Hello WordPress any key to continue. Any way for that dialogue to skip a line?

I understand this is a really silly thing to be messing around with but it feels kinda annoying. Any ideas?

Upvotes: 0

Views: 813

Answers (2)

user5681916
user5681916

Reputation: 1

Simply put an empty WriteLine under your last line.

Console::WriteLine("");

Upvotes: 0

NathanOliver
NathanOliver

Reputation: 180945

When writing to the stream you have to tell the stream when you want a newline. If you always want to make sure there is a newline before "press any key" then you can use the newline escape sequence '\n'

std::cout << "\nPlease enter any key to continue...";

Alternatively you can write a newline at then end of every output like

std::cout << "This is a line\n";
//or
std::cout << "this is a line" << std::endl;

Using endl will also flush the output stream.

Upvotes: 1

Related Questions