Hello world 출력해보기
Hello world 가장 기본적인 출력 방법 (std::cout )
#include <iostream> //입, 출력을 위한 필수 헤더파일
int _tmain(int args, _TCHAR* argv[]){
std::cout << "Hello world"; //출력해주는 함수(std::cout)에 "Hello world"를 보낸다는 뜻.
}
Hello world 뒤에 개행(엔터) 출력 (std::endl)
#include <iostream> //입, 출력을 위한 필수 헤더파일
int _tmain(int args, _TCHAR* argv[]){
std::cout << "Hello world" << std::endl;
}
중복되는 std:: 쓰지 않는 방법 1 (using 사용)
#include <iostream> //입, 출력을 위한 필수 헤더파일
using std::cout; //std::cout은 std::를 쓰지 않아도 된다.
using std::endl; //std::endl은 std::를 쓰지 않아도 된다.
int _tmain(int args, _TCHAR* argv[]){
cout << "Hello World" << endl;
}
중복되는 std:: 쓰지 않는 방법 2 (using 사용)
#include <iostream> //입, 출력을 위한 필수 헤더파일
using namespace std; //std::를 사용하는 모든 함수에 std::를 쓰지 않아도 된다.
int _tmain(int args, _TCHAR* argv[]){
cout << "Hello World" << endl;
}
using namespace std 를 사용해서 std의 모든 기능을 std:: 사용하지 않고 사용할 수 있지만 전체를 다 사용하는 것은 바람직하지 못한 방법이다.
printf를 사용
printf를 그대로 사용해도 상관없다. 그렇지만 std::cout은 데이터 형식을 지정하지 않아도 되고 사용이 더 편리해서 C++에서는 보통 std:cout을 사용한다.
C++ 개념 더보기
'◼️C++' 카테고리의 다른 글
[C++] 변수 선언 및 정의 (0) | 2023.08.31 |
---|---|
[C++] 자료형 (0) | 2023.08.31 |
[C++] 문자열 데이터 std::string (0) | 2023.08.31 |
[C++] Visual Studio 에서 추가로 사용하는 헤더파일 <stdafx.h> (0) | 2023.08.31 |
[C++] 여러 변수 출력하기 (0) | 2023.08.31 |