Printf Issues

A

Ao the Unstoppable

Hi. I'm pretty new to C/C++, and I was wondering how to correctly use
printf and then create a new line. What in printf creates a new line,
as if it was endl; in cout?

For example:

printf ("Hello World!");
printf ("How are you?");

How would I make it skip a line to output:

Hello World!
How are you?

....rather than:

Hellow World!How are you?

Thanks.
 
P

Phlip

Ao said:
printf ("Hello World!");
printf ("How are you?");

How would I make it skip a line to output:

Hello World!
How are you?

...rather than:

Hellow World!How are you?

Look up "escape codes" in the index of your least favorite tutorial.

\n

And it ain't a feature of printf, it's a feature of string and character
literals.
 
J

Jack Klein

Hi. I'm pretty new to C/C++, and I was wondering how to correctly use
printf and then create a new line. What in printf creates a new line,
as if it was endl; in cout?

For example:

printf ("Hello World!"); printf ("Hello World!\n");
printf ("How are you?"); printf ("How are you?\n");

How would I make it skip a line to output:

Hello World!
How are you?

...rather than:

Hellow World!How are you?

Thanks.

The newline escape sequence '\n' works in C++ streams as well.
 
R

rakesh k

Jack Klein said:
The newline escape sequence '\n' works in C++ streams as well.

you could use this:

printf ("Hello World!\nHow are you?");

'\n' is the newline character in c/c++
 
A

Andrew Koenig

Hi. I'm pretty new to C/C++, and I was wondering how to correctly use
printf and then create a new line.

Why do you want to use printf instead of << ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top