Istream函数汇总及输入函数总结
来源:互联网 发布:儿童上网控制软件 编辑:程序博客网 时间:2024/06/05 19:16
Ø gcount()
Return values
The extraction count.
Remarks
Use basic_istream::get to read unformatted characters.
Example
Ø get()
int_type get( );
basic_istream& get(
char_type& _Ch
);
basic_istream& get(char_type *_Str,
streamsize _Count);
basic_istream& get(
char_type *_Str,
streamsize _Count,
char_type _Delim
);
Return values
The parameterless form of get returns the element read as an integer or end of file. The remaining forms return the stream (*this).
Remarks
The first of these unformatted input functions extracts an element, if possible, as if by returning rdbuf->sbumpc. //遍历指针指向的区域
Otherwise, it returns traits_type::eof. If the function extracts no element, it calls setstate(failbit).
The second function extracts the int_type element meta the same way. If meta compares equal to traits_type::eof, the function calls setstate(failbit). Otherwise, it stores traits_type::to_char_type(meta) in _Ch. The function returns *this.
The third function returns get(_Str, _Count, widen('/n')).
The fourth function extracts up to _Count - 1 elements and stores them in the array beginning at _Str. It always stores char_type after any extracted elements it stores.
Example
Ø getline()
basic_istream& getline(
char_type *_Str,
streamsize _Count
);
basic_istream& getline(
char_type *_Str,
streamsize _Count,
char_type _Delim
);
Return Value
The stream (*this).
Remarks
The first of these unformatted input functions returns getline(_Str, _Count, widen('/n')).
The second function extracts up to _Count - 1 elements and stores them in the array beginning at _Str. It always stores the string termination character after any extracted elements it stores. If the function extracts no elements or _Count - 1 elements, it calls setstate(failbit). In any case, it returns *this
Example
Ø Read_s()
basic_istream& _Read_s(
char_type *_Str,
size_t _Str_size,
streamsize _Count
);
Return Value
The stream (*this).
Remarks
The unformatted input function extracts up to count elements and stores them in the array beginning at _Str. Extraction stops early on end of file, in which case the function calls setstate(failbit). In any case, it returns *this.
Example
Ø Readsome_s()
streamsize _Readsome_s(
char_type *_Str,
size_t _Str_size,
streamsize _Count
);
Return Value
The count of items in the buffer.
Remarks
The unformatted input function extracts up to count elements and stores them in the array beginning at _Str. If good is false, the function calls setstate(failbit). Otherwise, it assigns the value of rdbuf->in_avail to N. If N < 0, the function calls setstate(eofbit). Otherwise, it replaces the value stored in N with the smaller of _Count and N, and then calls read(_Str, N). In any case, the function returns gcount.
Example
Ø ignore()
basic_istream& ignore(
streamsize _Count = 1,
int_type _Delim = traits_type::eof( )
);
Return Value
The stream (*this).
Remarks
The unformatted input function extracts up to _Count elements and discards them. If _Count equals numeric_limits<int>::max, however, it is taken as arbitrarily large. Extraction stops early on end of file or on an element _Ch such that traits_type::to_int_type(_Ch) compares equal to _Delim (which is also extracted).
Example
Ø gets()
char *gets(
char* buffer
);
Return Values
Each function returns its argument if successful. A NULL pointer indicates an error or end-of-file condition. Use ferror or feof to determine which one has occurred.
Remarks
The gets function reads a line from the standard input stream stdin and stores it in buffer. The line consists of all characters up to and including the first newline character ('/n').
gets then replaces the newline character with a null character ('/0') before returning the line. In contrast, the fgets function retains the newline character.
Security Remarks
The string to be acquired must not be larger than the maximum number of bytes allowed in buffer; otherwise, a buffer overrun can occur.
This can lead to a denial of service attack against the application if an access violation occurs, or in the worst case, allow an attacker to inject executable code into your process. Consider using an appropriate strsafe function.
Example
Ø getchar()
int getchar(
void
);
Return Values
returns the character read.
To indicate an read error or end-of-file condition, getwchar return WEOF.
Remarks
Each routine reads a single character from a file at the current position and increments the associated file pointer (if defined) to point to the next character.
Example
输入函数的总结与对比
Andy总结于2010年7月10号 22:26:00
- Istream函数汇总及输入函数总结
- 输入流类(istream)常用成员函数
- 一些与输入有关的istream类成员函数
- std::istream::ignore() 函数
- C/C++——一些与输入有关的istream类成员函数
- 输入函数总结
- C++输入函数 总结
- C++输入函数总结
- 一些输入函数总结
- 输入函数总结
- IStream的Write和Seek函数
- istream类的一些成员函数
- MQL4内置函数--总结汇总
- 函数总结及函数练习
- c/c++输入函数总结
- istream::get,getline函数与string getline区别 istream::read 和ostream::write
- istream::get,getline函数与string getline区别 istream::read 和ostream::write
- istream::get,getline函数与string getline区别 istream::read 和ostream::write
- Virtual PC 中安 装ms dos 6.22
- 拥有奢侈品的人不一定是强者
- vc2008 office2007特性包的使用心得
- ListView 动态多重嵌套
- win32平台下互斥锁的实现
- Istream函数汇总及输入函数总结
- ppc 模拟器的安装、配置,以及一些常见问题及解决方法
- sql server系统表详细说明
- 动态创建Fastreport
- 整型
- linux下显示中文字体的几个必要条件
- IT人士必去的10个网站
- JQuery 中,使文本框获得焦点的方法
- 新手到来