방법 1 :
#include <iostream>
int main(void) {
std::cout << "Welcome to C++ Programming World" << std::endl;
return 0;
}
방법 2 :
#include <iostream>
int main(void) {
using namespace std;
cout << "Welcome to C++ Programming World" << endl;
return 0;
}
방법 3 : #include <stdio.h>를 하면 c언어의 표준 입출력 함수를 사용할 수 있다.
ㄴ #include <iostream>도 printf사용 가능하다.
#include <stdio.h> //<-stdio.h
int main(void) {
printf("이것도 된다.");
return 0;
}
#include <iostream> //<-iostream
int main(void) {
printf("요것도 된다.");
return 0;
}
============================================================================================
-cout는 가장 기본적인 출력객체이다
-cout는 namespace std에 정의되어 있다.
ㄴ이를 사용하기 위해 using namespace std라는 코드를 넣거나
std::cout 이렇게 써야한다(스코프연산자::)
-<<연산자가 삽입 연산자이다.
-endl은 개행이다 \n랑 똑같다.
-endl도 namespace std에 정의되어 있다.
============================================================================================
[변수출력하기]
#include <iostream>
int main(void) {
using namespace std;
int i;
cout << "숫자를 입력하세여 : ";
cin >> i;
if (i < 0)
cout << i<<"는 음수입니다. \n";
else if (i > 0)
cout << i<<"는 양수입니다. \n";
else if (i == 0)
cout << i<<"는 0입니다.\n";
return 0;
}
변수 i를 출력하려면,
cout << i<<"는 음수입니다. \n";
이렇게 해야된다.
cout<<변수이름<<"출력문";
책 : 이게 진짜 c++프로그래밍이다.이동익
'c++' 카테고리의 다른 글
5. [C++]while문 (0) | 2023.01.15 |
---|---|
4. [C++]for 반복문, 문자열(입력, 길이 등) (0) | 2023.01.15 |
3. switch-case문 (0) | 2023.01.15 |
1-2. 입력(cin), 공백으로 구분된 여러 숫자 입력 (0) | 2023.01.15 |
2. if문 (0) | 2023.01.15 |