본문 바로가기

c++18

c++ 데이타송수신 #include // std::byte를 위한 헤더 #include #include // std::unique_ptr를 위한 헤더 #include // std::memcpy를 위한 헤더 int main() { int sockfd; // 소켓 파일 디스크립터 // sockfd 초기화하는 코드... int header_length = 100; // 헤더의 길이 std::unique_ptr header(new std::byte[header_length]); // 헤더를 저장할 동적 배열 while (true) { ssize_t n = recv(sockfd, header.get(), header_length, 0); // 헤더 받기 if (n == -1) { // 에러 처리 코드... } int body_len.. 2023. 11. 13.
c++ soket통신 receive header와 body #include #include // std::byte를 위한 헤더 #include #include // std::copy를 위한 헤더 int main() { int sockfd; // 소켓 파일 디스크립터 // sockfd 초기화하는 코드... int header_length = 100; // 헤더의 길이 std::vector header(header_length); // 헤더를 저장할 동적 배열 while (true) { ssize_t n = recv(sockfd, header.data(), header.size(), 0); // 헤더 받기 if (n == -1) { // 에러 처리 코드... } header.resize(n); // 실제로 받은 데이터만큼 크기 조정 int body_length = .. 2023. 11. 10.
c++ 파일 라인 함수명 출력하는 매크로 #include void printLineAndFileFunction(int line, const char* file, const char* function) { std::cout 2023. 11. 7.
문자열 은 똑같은데 하나의 숫자만 가변일때 해결법 c++ #include #include #include int main() { std::string logMessage = "데이터 오류 때문에 0 행이(가) 로드되지 않았습니다."; std::regex errorMessageRegex("데이터 오류 때문에 (\\d+) 행이\\(가\\) 로드되지 않았습니다."); // 오류 메시지에 매칭되는 정규 표현식 std::smatch match; if (std::regex_search(logMessage, match, errorMessageRegex)) { std::string numberString = match[1].str(); // 추출된 숫자를 문자열로 저장 int number = std::stoi(numberString); // 문자열을 정수로 변환 std::c.. 2023. 11. 1.