函数原型: size_t fread( void buffer, size_t size, size_t count, FILE stream );
参 数:
1用于接收数据的地址(指针)(buffer)
2单个元素的大小(size) :单位是字节而不是位,例如读取一个整型数就是2个字节
3元素个数(count)
4提供数据的文件指针(stream)
返回值:成功读取的元素个数
给你一个例子 你看一下
#include <stdioh>
void main( void )
{
FILE stream;
char list[30];
int i, numread, numwritten;
/ Open file in text mode: /
if( (stream = fopen( "freadout", "w+t" )) != NULL )
{
for ( i = 0; i < 25; i++ )
list[i] = (char)('z' - i);
/ Write 25 characters to stream /
numwritten = fwrite( list, sizeof( char ), 25, stream );
printf( "Wrote %d items\n", numwritten );
fclose( stream );
}
else
printf( "Problem opening the file\n" );
if( (stream = fopen( "freadout", "r+t" )) != NULL )
{
/ Attempt to read in 25 characters /
numread = fread( list, sizeof( char ), 25, stream );
printf( "Number of items read = %d\n", numread );
printf( "Contents of buffer = %25s\n", list );
fclose( stream );
}
else
printf( "File could not be opened\n" );
}
list中是map,stream如何拿到key集合
liststream()map(m -> mkeySet())collect(CollectorstoSet());
// Q20:list中是map,stream如何拿到value集合
liststream()map(m -> mvalues())collect(CollectorstoSet());
以上就是关于文件函数fread()获取文件的内容的问题,在线等,急啊!全部的内容,包括:文件函数fread()获取文件的内容的问题,在线等,急啊!、list中是map,stream如何拿到key集合、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)