프로그래밍 _공부자료.60 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. std::byte 동적으로 메시지 수신받기 #include #include // std::byte를 위한 헤더 #include int main() { int sockfd; // 소켓 파일 디스크립터 // sockfd 초기화하는 코드... std::vector buffer(1024); // std::byte 타입의 동적 배열 ssize_t n = recv(sockfd, buffer.data(), buffer.size(), 0); // 메시지 받아 저장 if (n == -1) { // 에러 처리 코드... } buffer.resize(n); // 실제로 받은 데이터만큼 크기 조정 // buffer를 이용한 처리 코드... } 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. 이전 1 2 3 4 5 6 7 ··· 15 다음