您的位置:首页 > 编程语言 > C语言/C++

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

2015-06-18 15:07 691 查看
其实很简单, 做个记录。

#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。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: