본문 바로가기

C++4

C & C++ - 구조체 typedef struct alpha_s { string fruit = ""; string vegetable = ""; } alpha_t; typedef struct beta_s { string fruit = ""; string vegetable = ""; } beta_t; 구조체 배열에서 구조체 배열로 값을 넘겨줄 때 - for문은 int i를 선언하는 형태를 사용 - 구조체의 주소를 받는 포인터를 선언해서 값을 담기 2023. 3. 23.
C & C++ - string을 char*으로 변환 string example = "This is example how to change string to char*"; std::vector toCharStar( example.begin(), example.end() ); toCharStar.push_back('\0'); char* result = &toCharStar[0]; example >>> result로 형변환을 하였다. 출처 & 참고 : std::string을 const char*나 char*로 바꾸는 방법 std::string을 const char*나 char*로 바꾸는 방법 좀 알려주세요 hashcode.co.kr 2022. 10. 12.
C & C++ - char* 을 toupper/tolower로 변환하기 아스키 코드표에 기반한 숫자로 인식한다. tolower = int tolower(int c); char* toUpperOrToLower(char* change) { int length = (int)strlen(change); for(int i=0; i [C언어/C++] tolower, toupper 대문자 소문자 변경 안녕하세요. BlockDMask 입니다. 오늘은 C언어, C++에서 알파벳을 소문자는 대문자로, 대문자는 소문자로 변경해주는 tolower, toupper 함수에 대해서 알아보려고 합니다. 1. toupper, tolower 함수 원형 blockdmask.tistory.com 2022. 10. 12.
C & C++ - Vector의 unique, sort C++ Vector는 중복을 제거하여 담는 contains 기능이 없다. 이때, list를 담아 중복을 제거하는 작업을 하는데 unique는 연속적인 값 만을 제거한다. abcVector.erase(unique(abcVector.begin(), abcVector.end()), abcVector.end()); 따라서 사전 작업으로 sort 해줘야 한다. sort(abcVector.begin(), abcVector.end()); ========================================= C++에서 Vector contains는 std::find를 이용한다. Find는 지정 시점부터 끝지점까지 탐색해서 없으면 끝 지점을 반환한다. std::vector testList; for(int j=0; j 2022. 3. 23.