명품 C++ programming 12장 실습문제 14번


명품 C++ programming 12장 실습문제 14번

문제 read() 함수를 이용하여 c:\windows\system.ini 파일의 크기를 화면에 출력하는 프로그램을 작성하라. 이때 get() 함수나 seekg(), tellg() 함수를 사용하면 안된다. 내가 짠 코드 #include<iostream>#include<fstream>using namespace std;int main() { ifstream fin("c:\\windows\\system.ini", ios::in | ios::binary); if (!fin) { cout << "c:\\windows\\system.ini 열기 오류" << endl; } char ch[32] = { 0 }; int cnt = 0; while (!fin.eof()) { fin.read(ch, 32); int n = fin.gcount(); cnt += n; } cout << "파일의 크기는 " << cnt << " 입니다." << endl;}...



원문링크 : 명품 C++ programming 12장 실습문제 14번