int load(char * filaName , char *& buffer){ FILE *file; if((file = fopen("D://a.txt","r")) == NULL) { printf("cant open file!"); } fseek (file, 0, SEEK_END); // non-portable char *c = ""; int size=ftell (file); rewind (file); buffer = new char[size+1]; *(buffer+size) = 0; int result = fread(buffer,sizeof(char),size,file); if(fclose(file)) printf("file close error!"); return size; }
调用
int _tmain(int argc, _TCHAR* argv[]) { char *str; int size = load("",str); printf("%s",str); scanf("sad"); return 0; }