C++ 출력

1 개요[ | ]

C++ 출력
  • C++에서 Hello World 출력
#include <iostream>
using namespace std;

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

2 코드 분석[ | ]

#include <iostream>

include의 #은 전처리기에서 이 코드를 처리하라는 의미임 iostream은 헤더이며 프로그램 동작을 위한 각종 정보 포함

using namespace std;

네임스페이스 std(standard)를 쓰라는 의미

int main() { }

C++에서 프로그램의 시작은 main 함수{}는 함수의 시작과 끝을 말함

cout << "Hello World";

cout은 출력을 담당하며 stream 객체

3 여러 값[ | ]

  • 여러 값을 출력하기 위해서는 << 를 연결 해주면 됨.
#include<iostream>
using namespace std;

int main()
{
    cout << "ZETA" << "WIKI";
    return 0;
}
  • 출력
ZETAWIKI

4 다음줄[ | ]

  • endl는 다음줄로 이동해 주는 역활을 함.
#include <iostream>
using namespace std;

int main()
{
    cout << "ZETA" << endl;
    cout << "WIKI";
    return 0;
}
  • 출력
ZETA
WIKI

참고) endl대신 \n을 사용해도 동일한 결과를 얻을수 있음.

5 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}