今天介紹一個復制 粘貼的函數,用fstream實現
#include "stdafx.h" #include<iostream> #include<fstream> using namespace std; int main() { fstream in("a.jpg", ios_base::binary|ios_base::in); if (in.is_open()) { fstream out("F:/1/nature.jpg", ios_base::binary|ios_base::out); if (out.is_open()) { char* buf = new char[255]; while (in.good()) { in.read(buf, 255); int count = in.gcount(); out.write(buf, count); } out.close(); } in.close(); } return 0; }
示例展示:
原來的文件:
運行程序后: