c++ 读取全部txt文件内容到数组

来源:互联网 发布:微软官网的windows 7 编辑:程序博客网 时间:2024/04/27 20:48

其实很简单, 做个记录。


#include <stdlib.h>#include <stdio.h>#include <iostream>using namespace std;#include <string.h>void getformat(char *tmp){int len = strlen(tmp);}int main( void ){FILE *fp;fp = fopen("1.txt" , "r");fseek( fp , 0 , SEEK_END );int file_size;file_size = ftell( fp );printf( "%d" , file_size );// char *tmp;// tmp =  (char *)malloc( (file_size+1) * sizeof( char ) );char tmp[10000];fseek( fp , 0 , SEEK_SET);fread( tmp , file_size , sizeof(char) , fp);tmp[file_size] = '\0';fclose(fp);printf("%s" , tmp );return 0;}

over。


0 0
原创粉丝点击