c++读写文件
读取文件:
#include <stdio.h> void read() { FILE* f = fopen("E:/Desktop/1.jpg", "rb"); fseek(f, 0, SEEK_END); long size = ftell(f); rewind(f); unsigned char* data = new unsigned char[size]; fread(data, sizeof(char), size, f); fclose(f); }
写入文件:
#include <stdio.h> int main () { FILE * pFile; char buffer[] = { 'x' , 'y' , 'z' }; pFile = fopen ("myfile.bin", "wb"); fwrite (buffer , sizeof(char), sizeof(buffer), pFile); fclose (pFile); return 0; }
桂棹兮兰桨,击空明兮溯流光。