首页 > 编程知识 正文

linux system函数,read函数返回的是列表

时间:2023-05-06 13:41:39 阅读:27083 作者:4424

定义Read函数

read函数以一定长度读取文件中的数据,并将其存储在新数组中。 用于从文件读取数据。

函数原型istreamread(char*s,streamsize n );

参数char* s表示提取数据流的char型数组指针,streamsize n表示数组的长度

官方链接http://www.cplusplus.com/reference/istream/istream/read /? kw=read

使用Read函数的示例

#include //std:cout

#include //std:ifstream

int main () )。

STD : ifstream is (' test.txt ',STD :3360 ifstream 33603360 binary );

if(is ) {

//get length of file:

is.seekg(0,is.end );

int length=is.tellg (;

is.seekg(0,is.beg );

char * buffer=new char [length];

STD :3360 cout ' reading ' length ' characters . ';

//read data as a block:

is.read (缓冲区,长度);

是if(is )

STD : cout ' allcharactersreadsuccessfully.';

else

STD : cout ' error : only ' is.gcount () ' could be read ';

is.close (;

//buffercontainstheentirefile .

delete[] buffer;

}

返回0;

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。