책 정리/Reference C++ C++ I/O Stream : 바이너리 파일 읽고 쓰기 최익필 2008. 11. 29. 04:56 예제코드 #include <iostream> #include <fstream> #include <vector> int main( void ) { std::ifstream infile ( "old.txt",std::ifstream::binary); std::ofstream outfile ("new.txt",std::ofstream::binary); // infile 용의 파일 크기 구함 infile.seekg(0,std::ifstream::end); long size=infile.tellg(); infile.seekg(0); // char 형태로 메모리 생성 std::vector<char> buf( size ); // 파일 읽어서 buffer 에 쌓아 둠 infile.read( &buf[0], size); // 그리고 그것을 outfile 에 씀 outfile.write ( &buf[0], size); }