일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- MongoDB
- 우리들교회
- Big Data
- data science
- WebGL
- 통계
- 김양재
- 주일설교
- Artificial Intelligence
- Machine Learning
- 김양재 목사님
- probability
- R
- 몽고디비
- node.js
- Statistics
- c++
- 빅 데이타
- 김양재 목사
- No SQL
- 빅데이타
- 확률
- openCV
- nodeJS
- 데이터 과학
- 빅데이터
- 빅 데이터
- 딥러닝
- Deep learning
- 인공지능
- Today
- Total
Scientific Computing & Data Science
[C/C++] Example / Reading & Writing to a Binary File 본문
[C/C++] Example / Reading & Writing to a Binary File
cinema4dr12 2014. 6. 12. 10:56// // main.cpp // // Created by gchoi on 2014. 5. 8.. // Copyright (c) 2014년 gchoi. All rights reserved. // #include <iostream> #include <fstream> #include <strstream> const int MAX_SIZE = 2048; using namespace std; int main(int argc, const char * argv[]) { string filename1 = "{YOUR_FILE_PATH}/img0.jpg"; string filename2 = "{YOUR_FILE_PATH}/img1.jpg"; char buff[MAX_SIZE]; ifstream ifs(filename1.c_str(), ios::in | ios::binary); if(!ifs) { cerr << "can't open input file" << endl; exit(1); } ofstream ofs(filename2.c_str(), ios::out | ios::trunc | ios::binary); if(!ofs) { cerr << "can't open output file" << endl; exit(1); } while(!ifs.eof()) { ifs.read(buff, MAX_SIZE); ofs.write(buff, ifs.gcount()); } ifs.clear((ios::eofbit | ios::failbit) ^ ifs.rdstate()); if(ifs.good() && ofs.good()) cout << "correct" << endl; else cout << "bad\n" << "state of ifs : " << ifs.rdstate() << "\nstate of ofs : " << ofs.rdstate() << endl; ifs.close(); ofs.close(); return 0; }
'Programming > C&C++' 카테고리의 다른 글
[C/C++] Example / Vector Class (0) | 2014.06.12 |
---|---|
[C/C++] Example / 최대공약수(GCM) 알고리즘 (0) | 2014.06.12 |
[C/C++] Example / Reading a File (0) | 2014.06.12 |
[C/C++] Example / Writing a File (0) | 2014.06.12 |
[C/C++] Example / Ordering - Descending Algorithms (0) | 2014.06.12 |