[C++] 1.4 입출력 스트림
2021. 3. 17. 22:23ㆍProgramming Language/.Cpp
1.4 입출력 스트림 - cin,cout,endl
cin → console in
cout → console out
endl → end line
#include <iostream> // cout, cin, endl...
#include <cstdio> //printf
int multiplyNumbers(int a, int b)
{
int sum = a * b;
return sum;
}
int main()
{
using namespace std;
cout << "a+b = " << multiplyNumbers(1, 2) << endl;
return 0;
}
메모리에서 벌어지는 일
- mulyiplyNumber(1,2) 함수가 실행되면, 매개변수인 a와 b가 생성되고 1과 2라는 값이 초기화 된다.
- endl;과 \nBecause of this, use of the ‘\n’ character is typically preferred instead. The ‘\n’ character moves the cursor to the next line, but doesn’t do the redundant flush, so it performs better. The ‘\n’ character also tends to be easier to read since it’s both shorter and can be embedded into existing text.
- Using std::endl can be a bit inefficient, as it actually does two jobs: it moves the cursor to the next line, and it “flushes” the output (makes sure that it shows up on the screen immediately). When writing text to the console using std::cout, std::cout usually flushes output anyway (and if it doesn’t, it usually doesn’t matter), so having std::endl flush is rarely important.
- std 참고
'Programming Language > .Cpp' 카테고리의 다른 글
[C++ STL과 알고리즘] 벡터의 merge sort 공부하기 (0) | 2022.01.13 |
---|---|
[C++] BOJ 1026번 : 보물 (0) | 2022.01.09 |
연산자 오버로딩 (0) | 2021.12.27 |
[C++] 1.10 선언과 정의 (0) | 2021.03.17 |
[C++] 1.5 함수와의 첫 만남 - 인풋을 저장해 계산하기 (0) | 2021.03.17 |