[c++] 파일 정보 얻기
아래는 파일의 크기를 가져오는 예제 코드입니다:
#include <iostream>
#include <fstream>
int main() {
std::ifstream file("example.txt", std::ios::binary | std::ios::ate);
if (file.is_open()) {
std::streamsize size = file.tellg();
file.close();
std::cout << "파일 크기: " << size << "바이트" << std::endl;
}
else {
std::cerr << "파일을 열 수 없습니다." << std::endl;
}
return 0;
}
이 코드는 example.txt
파일을 열고, 파일 크기를 가져와 화면에 출력합니다.
파일의 다른 정보(예: 생성 일자, 수정 일자 등)를 가져오고 싶다면, 플랫폼에 따라 다른 방법이 있을 수 있습니다. 윈도우즈 환경에서는 WinAPI를 사용하여 파일 정보를 가져올 수도 있습니다.
이와 관련된 더 많은 정보는 다음 문서를 참고하시기 바랍니다:
- https://cppreferences.com/w/cpp/filesystem/status
- https://en.cppreference.com/w/cpp/filesystem/file_status