雪铁龙c5新车多少钱:c++ 里 istream read()的用法
来源:百度文库 编辑:偶看新闻 时间:2024/04/30 11:14:27
c++里 istream read()的用法2010-05-19 19:18
If the End-of-File is reached before n characters have been read, the array will contain all the elements read until it, and the failbit and eofbit will be set (which can be checked with members fail and eof respectively).
Notice that this is an unformatted input function and what is extracted is not stored as a c-string format, therefore no ending null-character is appended at the end of the character sequence.
Calling member gcount after this function the total number of characters read can be obtained.
Errors are signaled by modifying the internal state flags:
flag error eofbit The end of the source of characters is reached before n characters have been read. This also sets failbit. failbit The end of the source of characters is reached before n characters have been read. This also sets eofbit. badbit An error other than the above happened.
Additionaly, in any of these cases, if the appropriate flag has been set with member function ios::exceptions, an exception of type ios_base::failure is thrown.
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Read block of data
Reads a block of data of n characters and stores it in the array pointed by s.If the End-of-File is reached before n characters have been read, the array will contain all the elements read until it, and the failbit and eofbit will be set (which can be checked with members fail and eof respectively).
Notice that this is an unformatted input function and what is extracted is not stored as a c-string format, therefore no ending null-character is appended at the end of the character sequence.
Calling member gcount after this function the total number of characters read can be obtained.
Parameters
- s
- Pointer to an allocated block of memory where the content read will be stored.
- n
- Integer value of type streamsize representing the size in characters of the block of data to be read.
Return Value
The functions return *this.Errors are signaled by modifying the internal state flags:
Additionaly, in any of these cases, if the appropriate flag has been set with member function ios::exceptions, an exception of type ios_base::failure is thrown.
Example
12
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// read a file into memory
#include
#include
using namespace std;
int main () {
int length;
char * buffer;
ifstream is;
is.open ("test.txt", ios::binary );
// get length of file:
is.seekg (0, ios::end);
length = is.tellg();
is.seekg (0, ios::beg);
// allocate memory:
buffer = new char [length];
// read data as a block:
is.read (buffer,length);
is.close();
cout.write (buffer,length);
delete[] buffer;
return 0;
}
c语言 read问题
词典里()中的C、U是什么意思?
C*C=2C里*是什么意思?
All of us enjoyed__your artilcles in the school magazine.A.read B.reading C.to read D.readed选择题?
为什么系统里的很多程序不能“READ”或“WIRTEEN”
谁能解释一下fortran中的read语句里的fmt
I can read ( ) newspaper.括号里填什么呢?
(求助)关于内存不能为“read”
ox7c92 16c引用的oxoo236000内寸.该指令不能为read,怎么办?
选择题:The conductor begins to ____the ticket. A.watch B. see C.look D.read
Unable to read TLD "META-INF/c.tld" from JAR file
access violation at address 01307875 in module IE_helper class.dll read ofaddress 0000000c
Access violation at ADDRESS 004673al inmudule xjpkclient dat read of address 0000056c是什么意思?
我的C盘里目录里出现了这样的文件(文本文档)
系统C 里的问题
C语言里这些是什么意思?
C盘里的WINDOWS
C语言 里 flag 是什么?
C语言里,保龄球问题
WINDOWS下的DOWNLOAD里保存视频为什么老提示内存不能为READ?病毒?
怎么样装C语言呀?为什么我每次装的时候它都说什么不能read啊?
Access violaton at address 004673Ar in module" Mirclient.dit ".Read of address 0000056C.
(那个人手中是否握着M-I-C) 谁是MVP里的 M-I-C 是什么意思?/
Read in the sun, please. (改为否定句)