C++/C++ Common15 Endian 변환 시스템 엔디안 감지엔디안 변환#include #include #include // 엔디안 변환 함수uint16_t swap_endian_16(uint16_t val) { return (val > 8);}uint32_t swap_endian_32(uint32_t val) { return ((val >> 24) & 0x000000FF) | ((val >> 8) & 0x0000FF00) | ((val > 56) & 0x00000000000000FF) | ((val >> 40) & 0x000000000000FF00) | ((val >> 24) & 0x0000000000FF0000) | ((val >> 8) &.. 2024. 6. 26. 함수 결과 처리 코드 간소 원래 내용ENUM_VALUE enum_value = TestFunction();switch (enum_value){ case ENUM_VALUE::SUCC; LogNormal("SUCC"); return enum_value; case ENUM_VALUE::FAIL; LogError("FAIL"); return enum_value; case ENUM_VALUE::ABORT; LogInfo("ABORT"); return enum_value; case ENUM_VALUE::RETRY; LogInfo("RETRY"); return enum_value;} 매크로 이용#include enu.. 2024. 5. 29. 가변 인수 매크로 #include "pch.h" #pragma warning(disable: 4793) // methods are compiled as native (clr warning) #include #include #include #include using namespace std; using namespace System; #define Log(fmt, ...) _log(__FILE__, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__) void _log(const char* filePath, const char* funcName, const int lineNum, const char* fmt, ...); void ShowQwerty(); void ShowNumber(); int ma.. 2023. 3. 30. Time #include "pch.h" #include #include #include #include using namespace std; using namespace System; void ShowCurrentTime_Seconds(); void ShowCurrentTime(); void ShowElapsedTime(); int main() { ShowCurrentTime_Seconds(); ShowCurrentTime(); ShowElapsedTime(); std::string str; std::getline(std::cin, str); return 0; } void ShowCurrentTime_Seconds() { cout 2023. 3. 30. Bit Shift #include "pch.h" #include #include #include using namespace std; using namespace System; int main() { // 0000010000000000 1024 // 0000001000000000 1024 >> 1 // 0000000000000001 1024 >> 10 // 0000000000000000 1024 >> 11 // 0000000000000010 1024 >> 10 2023. 3. 27. 시간 출력 #include #include #include using namespace std; time_t GetUnixTime() { time_t tt; tt = time(NULL); return tt; } int GetUnixTimeSecond() { return (int)GetUnixTime(); } string GetTimeString() { time_t tt = GetUnixTime(); struct tm t; localtime_s(&t, &tt); //char -> std::string.c_str() 변환 필요 char timeChars[200]; memset(timeChars, 0x00, 200); sprintf_s(timeChars, sizeof(timeChars), "%04d-%02d-%02d %.. 2022. 11. 5. string formatting #include #include #include #include using namespace std; template std::string StringFormat(const std::string& format, Args ... args) { int bufSize = std::snprintf(nullptr, 0, format.c_str(), args ...) + 1; if (bufSize 2022. 8. 9. string split #include #include #include #include using namespace std; vector StringSplit(string sourceString, char delimeter) { vector ss; string::size_type prevPos = 0, curPos = 0; while ((curPos = sourceString.find(delimeter, curPos)) != std::string::npos) { string substring(sourceString.substr(prevPos, curPos - prevPos)); ss.push_back(substring); prevPos = ++curPos; } ss.push_back(sourceString.substr(prev.. 2022. 8. 8. string 선언 string str1("ABCDE"); string str2 = "12345"; string str3(str1); 데이터 순환 for (int i = 0; i < str1.size(); i++) { cout 2022. 8. 6. queue 선언 queue queue1; 마지막 요소에 데이터 추가 queue1.push(11); queue1.push(22); queue1.push(33); queue1.push(44); queue1.push(55); 첫번째 요소 데이터 조회 queue1.front() 첫번째 요소 데이터 추출 queue1.pop(); 큐가 비어있는지 확인 queue1.empty(); 데이터 순환 size = (int)queue1.size(); for (int i = 0; i < size; i++) { printf("%d \n", queue1.front()); queue1.pop(); } printf("queue1 size(%d) = %zd \n\n", queue1.empty(), queue1.size()); 데이터 교체 queu.. 2022. 8. 6. map map 은 Key 값을 기준으로 중복 데이터가 불가 선언 map map1; 데이터 추가 map1.insert({ "1st", 111 }); map1.insert({ "2nd", 222 }); map1.insert({ "3rd", 333 }); map1.insert({ "4th", 444 }); map1.insert({ "5th", 555 }); 데이터 변경 map1["1st"] = 1; map1["Last"] = 999; 데이터 찾기 및 삭제 iter = map1.find("4th"); if (iter == map1.end()) { printf("4th not found \n"); } else { cout 2022. 8. 6. list 선언 list list1; 리스트 뒤에 데이터 추가 list1.push_back(44); list1.push_back(55); 리스트 앞에 데이터 추가 list1.push_front(33); list1.push_front(22); list1.push_front(11); 리스트 특정 위치에 데이터 추가 iter = list1.begin(); iter++; list1.insert(iter, 777777); list1.insert(iter, 888888); list1.insert(iter, 999999); 리스트 최초 요소 데이터 조회 printf("first element : %d \n\n", list1.front()); 리스트 마지막 요소 데이터 조회 printf("last element : %d \n\n.. 2022. 8. 6. vector 선언 vector vec1; 마지막 요소에 데이터 추가 vec1.push_back(10); vec1.push_back(20); 마지막 요소의 데이터 삭제 vec1.pop_back(); 특정 요소 삭제 (0 base 에서 4, 5 번 요소 삭제) vec1.erase(vec1.begin() + 3, vec1.begin() + 5); 전체 데이터 삭제 vec1.clear(); 데이터 순환 for (iter = vec1.begin(); iter != vec1.end(); ++iter) { printf("%d \n", (int)(*iter)); } printf("vec1 size = %zd \n\n", vec1.size()); 데이터 복사 vector vec2 = vector(vec1.begin(), vec1.b.. 2022. 8. 6. STL STL(Standard Template Library) 템플릿을 사용하여 자료형에 관계없이 범용적인 프로그래밍을 가능하게 하는 라이브러리 STL 구성 요소 Container 기본 자료형 또는 사용자 정의 자료형을 담는 자료 구조 클래스 형태 컨테이너에 보관된 원소(element)에 대한 접근 함수 제공 Algorithm 동일한 기능을 제공하는 함수 Iterator Container 의 자료형에 관계 없이 Algorithm 이 동작하도록 하는 매개체 서로 다른 자료 구조를 동일한 방식으로 핸들링 할수 있도록 포인터를 추상화한 형태 컨테이너의 메모리 주소를 나타낸다. Container 종류 종류 자료형 특성 Sequential Container array vector deque list forward_lis.. 2022. 8. 6. Callback function Callback function EXE 함수를 DLL 에서 호출 DLL extern "C" __declspec(dllexport) void __stdcall DLL_SetErrorFunction(LPVOID fp); caller.h void(*fpErrorFunction)(int errorNum); void ErrorFunction(int errorNum); void SetErrorFunction(LPVOID fp); caller.cpp caller() { fpErrorFunction = NULL; } void caller::SetErrorFunction(LPVOID fp) { fpErrorFunction = (void(__cdecl*)(int))fp; } void caller::ErrorFunction.. 2022. 7. 18. 이전 1 다음