C++ 헤더 메소드 정리(코테용)

서재혁·2022년 7월 31일
0

C++

목록 보기
3/7

iostream

기본 입출력 함수

stdio.h

printf, scanf를 사용하기 위함

cstdlib

1. 메모리 할당

// void* aligned_alloc(size_t alignment, size_t size); 						// Unsupported in MSVC
void* calloc(size_t nmemb, size_t size);
void free(void* ptr);
void* malloc(size_t size);
void* realloc(void* ptr, size_t size);

2. 숫자 문자열 변환

사용시 string 변수는 c_str() 메소드를 이용하여 변환

double atof(const char* nptr); 
int atoi(const char* nptr);	
long int atol(const char* nptr);
long long int atoll(const char* nptr);
double strtod(const char* nptr, char** endptr);
float strtof(const char* nptr, char** endptr);
long double strtold(const char* nptr, char** endptr);
long int strtol(const char* nptr, char** endptr, int base);
long long int strtoll(const char* nptr, char** endptr, int base);
unsigned long int strtoul(const char* nptr, char** endptr, int base);
unsigned long long int strtoull(const char* nptr, char** endptr, int base);

3. 알고리즘 함수

void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, c-compare-pred * compar);
void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, compare-pred * compar);
void qsort(void* base, size_t nmemb, size_t size, c-compare-pred * compar);
void qsort(void* base, size_t nmemb, size_t size, compare-pred * compar);

4. 저품질 난수 생성 함수

int rand();
void srand(unsigned int seed);

5. 절대값

int abs(int j);
long int abs(long int j);
long long int abs(long long int j);
float abs(float j);
double abs(double j);
long double abs(long double j);
long int labs(long int j);
long long int llabs(long long int j);

6. 정수 나누기

div_t div(int numer, int denom);
ldiv_t div(long int numer, long int denom);
lldiv_t div(long long int numer, long long int denom);
ldiv_t ldiv(long int numer, long int denom);
lldiv_t lldiv(long long int numer, long long int denom);

string

1. getline

https://velog.io/@twg0/C%EC%9E%85%EC%B6%9C%EB%A0%A5

2. stod

문자 시퀀스를 double으로 변환합니다.

double stod(const string& str, size_t* idx = 0);

3. stoi

문자 시퀀스를 정수로 변환합니다.

int stoi(const string& str,size_t* idx = 0, int base = 10);

4. stoll

문자 시퀀스를 long long으로 변환합니다.

long long stoll( const string& str, size_t* idx = 0, int base = 10);

5. swap

두 문자열의 문자 배열을 교환합니다.

template <class Traits, class Allocator>
void swap(basic_string<CharType, Traits, Allocator>& left, basic_string<CharType, Traits, Allocator>& right);

예제

	string s1 ( "Tweedledee" );
   	string s2 ( "Tweedledum" );

   	swap ( s1 , s2 );
    cout << "\nAfter swapping string s1 and s2:" << endl;
   	cout << "The basic_string s1 = " << s1 << "." << endl;
   	cout << "The basic_string s2 = " << s2 << "." << endl;
    
    /*출력
    After swapping string s1 and s2:
	The basic_string s1 = Tweedledum.
	The basic_string s2 = Tweedledee.
	*/

6. to_string

값을 string으로 변환합니다.

string to_string(int value);
string to_string(unsigned int value);
string to_string(long value);
string to_string(unsigned long value);
string to_string(long long value);
string to_string(unsigned long long value);
string to_string(float value);
string to_string(double value);
string to_string(long double value);

algorithm

정렬된 범위의 요소가 지정된 값과 같은지 아니면 이진 조건자가 지정한 의미에서 해당 요소와 같은지 테스트합니다.
이진 탐색

ex) bool binary_search(vector.begin(), vector.end(), int target,(pred))

2. clamp

상한, 하한을 정해놓고 싶을 때 사용하는 함수

ex) clamp(변수, 하한, 상한)

3. copy

iterator를 기준으로 데이터를 복사하는 함수

ex) copy(원본 시작 iter, 원본 끝 iter, 복사 받는 시작 iter)

결과: 붙여넣기 X 덮어쓰기 O

4. count

범위에 존재하는 타겟 요소 갯수를 구하는 함수

ex) count(시작 iter, 끝 iter, target)

5. fill

지정한 범위에 새로운 요소를 할당하는 함수

ex) fill(시작 iter, 끝 iter, 새로운 요소)

6. find

범위에서 지정된 값을 가진 요소가 첫 번째로 나타나는 위치를 반환하는 함수

ex) find(시작 iter, 끝 iter, target)

7. for_each

범위에서 각각의 요소마다 특정 함수를 호출하는 함수

ex) for_each(시작 iter, 끝 iter, 특정 함수)

지정된 함수에 각각의 요소가 자동으로 인수로써 작동한다.

8. max/min_element

지정된 범위에서 가장 큰/작은 요소를 반환합니다.

ex) *max_element(시작 iter, 끝 iter) // min 도 동일

9. sort

지정된 범위에 있는 요소를 오름차순/내림차순 등의 기준으로 정렬합니다.

ex) sort(시작 iter, 끝 iter, compare)

10. unique

지정된 범위에서 인접한 중복 요소를 제거한다.

ex) unique(시작 iter, 끝 iter)

11. lower/upper_bound

lower_bound : 지정된 값보다 크거나 같은 값이 있는 정렬된 범위에서 첫 번째 요소의 위치를 찾는다.
upper_bound : 지정된 값보다 큰 값이 있는 정렬된 범위에서 첫 번째 요소의 위치를 찾는다.

ex) lower_bound(시작 iter, 끝 iter, 값)
profile
조금만 더

0개의 댓글