본문 바로가기

공부/C++

C++ 자료형 Max 값

( Windows 10 - 64bit 에서 테스트 )

#include <limits>의 template numeric_limits를 사용.

 

더보기
#include <iostream>
#include <limits>
#include <sstream>

ostringstream os;
cout << "-- signed --" << endl;
cout << "char\t\t\t:\t" << (int) numeric_limits< char >::min() << " ~ " << (int) numeric_limits< char >::max() << endl;
cout << "wchar_t\t\t\t:\t" << (int) numeric_limits< wchar_t >::min() << " ~ " << (int) numeric_limits< wchar_t >::max() << endl;
cout << "char16_t\t\t:\t" << (int) numeric_limits< char16_t >::min() << " ~ " << (int) numeric_limits< char16_t >::max() << endl;
cout << "short\t\t\t:\t" << numeric_limits< short >::min() << " ~ " << numeric_limits< short >::max() << endl;
cout << "short int\t\t:\t" << numeric_limits< short int >::min() << " ~ " << numeric_limits< short int >::max() << endl;
cout << "int\t\t\t:\t" << numeric_limits< int >::min() << " ~ " << numeric_limits< int >::max() << endl;
cout << "long\t\t\t:\t" << numeric_limits< long >::min() << " ~ " << numeric_limits< long >::max() << endl;
cout << "float\t\t\t:\t" << numeric_limits< float >::min() << " ~ " << numeric_limits< float >::max() << endl;
cout << "long float\t\t:\t" << numeric_limits< long float >::min() << " ~ " << numeric_limits< long float >::max() << endl;
cout << "double\t\t\t:\t" << numeric_limits< double >::min() << " ~ " << numeric_limits< double >::max() << endl;
cout << "long double\t\t:\t" << numeric_limits< long double >::min() << " ~ " << numeric_limits< long double >::max() << endl;
cout << "long int\t\t:\t" << numeric_limits< long int >::min() << " ~ " << numeric_limits< long int >::max() << endl;
os << numeric_limits< long long >::min() << " ~ " << numeric_limits< long long >::max();
cout << "long long\t\t:\t" << os.str() << endl; os.clear(); os.str( "" );
os << numeric_limits< long long int>::min() << " ~ " << numeric_limits< long long int>::max();
cout << "long long int\t\t:\t" << os.str() << endl; os.clear(); os.str( "" );

cout << endl << "-- unsigned --" << endl;
cout << "unsigned char\t\t:\t" << (int) numeric_limits< unsigned char >::min() << " ~ " << (int) numeric_limits< unsigned char >::max() << endl;
cout << "unsigned wchar_t\t:\t" << "invalid combination of type specifiers" << endl;
cout << "unsigned char16_t\t:\t" << "invalid combination of type specifiers" << endl;
cout << "unsigned short\t\t:\t" << numeric_limits< unsigned short >::min() << " ~ " << numeric_limits< unsigned short >::max() << endl;
cout << "unsigned short int\t:\t" << numeric_limits< unsigned short int >::min() << " ~ " << numeric_limits< unsigned short int >::max() << endl;
cout << "unsigned int\t\t:\t" << numeric_limits< unsigned int >::min() << " ~ " << numeric_limits< unsigned int >::max() << endl;
cout << "unsigned long\t\t:\t" << numeric_limits< unsigned long >::min() << " ~ " << numeric_limits< unsigned long >::max() << endl;
cout << "unsigned float\t\t:\t" << "invalid combination of type specifiers" << endl;
cout << "unsigned long float\t:\t" << "invalid combination of type specifiers" << endl;
cout << "unsigned double\t\t:\t" << "invalid combination of type specifiers" << endl;
cout << "unsigned long double\t:\t" << "invalid combination of type specifiers" << endl;
cout << "unsigned long int\t:\t" << numeric_limits< unsigned long int >::min() << " ~ " << numeric_limits< unsigned long int >::max() << endl;
os << numeric_limits< unsigned long long >::min() << " ~ " << numeric_limits< unsigned long long >::max();
cout << "unsigned long long\t\t:\t" << os.str() << endl; os.clear(); os.str( "" );
os << numeric_limits< unsigned long long int>::min() << " ~ " << numeric_limits< unsigned long long int>::max();
cout << "unsigned long long int\t\t:\t" << os.str() << endl; os.clear(); os.str( "" );
cout << endl << endl << endl;

'공부 > C++' 카테고리의 다른 글

[정리중] C++ 디자인 패턴 종류  (0) 2019.09.10
STL Container  (0) 2019.08.21
C++ 키워드 ( 정리 중 )  (1) 2019.06.17