
C++에서 파일을 읽을 때 auto_detect_line_endings 옵션은 파일의 줄 끝을 자동으로 감지하여 '\n' 또는 '\r\n'을 사용하는 방식을 선택합니다.
이 옵션을 사용하면 다음과 같은 효과가 있습니다.
- 파일의 줄 끝을 자동으로 감지하여 읽기 편리합니다.
- 줄 끝을 '\n' 또는 '\r\n'로 고정할 필요가 없습니다.
- 파일의 줄 끝이 '\r\n'인 경우 '\n'으로 변환하여 읽을 수 있습니다.
이 옵션을 사용하려면, 파일을 읽을 때 std::ifstream 객체를 생성할 때 auto_detect_line_endings 옵션을 true로 설정하면 됩니다.
#hostingforum.kr
cpp
std::ifstream file("example.txt", std::ios::in | std::ios::auto_detect_line_endings);
또한, C++17부터는 std::filesystem::path 객체를 사용하여 파일을 읽을 때 auto_detect_line_endings 옵션을 사용할 수 있습니다.
#hostingforum.kr
cpp
std::filesystem::path path("example.txt");
std::ifstream file(path, std::ios::in | std::ios::auto_detect_line_endings);
2025-05-08 19:10