출력개수가 주어지지 않은 경우

hyun20·2021년 7월 18일
0

백준 10951번 A+B-4

방법1

#include <iostream>
using namespace std;
int main() {
	int a, b;
	while(cin>>a>>b){
		cout << a + b << endl;
	}
}

EOF: End of File

방법2

#include <iostream>
using namespace std;
int main() {
	int a, b;
	while(scanf_s("%d %d",&a,&b)!=EOF){
		cout << a + b << endl;
	}
}

scanf와 scanf_s의 차이
scanf(): 형식 지정자에 맞춰 값을 입력받음-->값을 할당된 메모리 주소에 넣음
#define_CRT_SECURE_NO_WARNINGS 쳐주면 사용 가능
scanf는 버퍼 오버플로우 발생-->보완 : scanf_s
scanf_s 사용법
scanf_s("입력받을 형태",&변수이름, 입력받을 크기)
단일문자, 하나의 문자열일 경우 크기 생략 가능

0개의 댓글