C 读写文件:
File *fp;
fp = fopen(const char* filename, const char* mode); //mode = "r" "w" "a" "r+" "w+"
int fputc(int a, fp); //put a char to fp, and return the value of a
char c = fgetc(fp); //
int fseek(fp, int offset, int whence);
fputs(char *, fp);
fgets(str, int size, fp);
fprintf(fp, fmt, arguments);
fscanf(fp, fmt, &arguments);
fread(void *ptr, size_t size, size_t n, fp);
fwrite(const void* ptr, size_t size, n, fp);
C++读写文件:
读:ifstream if("a.txt");
或者
ifstream if;
if.open("a.txt");
if>>variable; //空格作为结束符
if.getline(string line);
getline(if,string line );
写:ofstream if("a.txt");
或者
ofstream if;
of.open("a.txt");
of<
阅读(2223) | 评论(0) | 转发(0) |