출력하기

cout 객체에 << 를 함께 사용하면 텍스트를 출력할 수 있습니다.

예제

#include <iostream>
using namespace std;

int main() {
   cout << "Hello World!";
   return 0;
}
Hello World!


여러 개의 cout 객체를 추가할 수 있습니다.

예제

#include <iostream>
using namespace std;

int main() {
   cout << "Hello World!";
   cout << "I am learning C++";
   return 0;
}
Hello World!I am learning C++

하지만 줄 넘김이 이루어지지는 않습니다.



줄 넘기기

\n 을 두 번 입력하면 줄 넘김을 두 번해서 빈 줄이 하나 생깁니다.

예제

#include <iostream>
using namespace std;

int main() {
   cout << "Hello World! \n\n";
   cout << "I am learning C++";
   return 0;
}
Hello World!

I am learning C++


endl 을 이용해서 줄 넘김을 할 수도 있습니다.

#include <iostream>
using namespace std;

int main() {
   cout << "Hello World!" << endl;
   cout << "I am learning C++";
   return 0;
}
Hello World!
I am learning C++

\nendl 모두 줄 넘김에 사용할 수 있지만, \n 이 더 자주 쓰이고 바람직한 방식입니다.