Anyone can give an example of
登录 | 论坛导航 -> 华新鲜事 -> 求学狮城 | 本帖共有 3 楼,分 1 页, 当前显示第 1 页 : 本帖树形列表 : 刷新 : 返回上一页
<<始页  [1]  末页>>
作者:香陵居士 (等级:16 - 好恐怖呀,发帖:22662) 发表:2003-02-20 06:15:49  楼主  关注此帖
Anyone can give an example of
program which deals with formatted input in C++?
最新推出专栏《倾听索罗斯》 欢迎大家前来捧场!

Yeah!
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:Yup (等级:3 - 略知一二,发帖:858) 发表:2003-02-20 21:11:02  2楼 评分:
可以用 istream::get()
( 例如: cin.get() ),具体如下


int get();&

istream& get( char* pch, int nCount, char delim = '\n' );

istream& get( unsigned char* puch, int nCount, char delim = '\n' );

istream& get( signed char* psch, int nCount, char delim = '\n' );

istream& get( char& rch );

istream& get( unsigned char& ruch );

istream& get( signed char& rsch );

istream& get( streambuf& rsb, char delim = '\n' );

Parameters

pch, puch, psch

A pointer to a character array.

nCount

The maximum number of characters to store, including the terminating NULL.

delim

The delimiter character (defaults to newline).

rch, ruch, rsch

A reference to a character.

rsb

A reference to an object of a streambuf-derived class.

Remarks

These functions extract data from an input stream as follows:

Variation Description
get(); Extracts a single character from the stream and returns it.

get( char*, int, char ); Extracts characters from the stream until either delim is found, the limit nCount is reached, or the end of file is reached. The characters are stored in the array followed by a null terminator.

get( char& ); Extracts a single character from the stream and stores it as specified by the reference argument.

get( streambuf&, char ); Gets characters from the stream and stores them in a streambuf object until the delimiter is found or the end of the file is reached. The ios::failbit flag is set if the streambuf output operation fails.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:Yup (等级:3 - 略知一二,发帖:858) 发表:2003-02-20 21:12:54  3楼 评分:
可以用 istream::get()( 例如: cin.get() ),具体如下 int get();& istream& get( char* pch, int nCount, char delim = '\n' ); istream& get( unsigned char* puch, int nCount, char delim = '\n' ); istream& get( signed char* psch, int nCount, char delim = '\n' ); istream& get( char& rch ); istream& get( unsigned char& ruch ); istream& get( signed char& rsch ); istream& get( streambuf& rsb, char delim = '\n' ); Parameters pch, puch, psch A pointer to a character array. nCount The maximum number of characters to store, including the terminating NULL. delim The delimiter character (defaults to newline). rch, ruch, rsch A reference to a character. rsb A reference to an object of a streambuf-derived class. Remarks These functions extract data from an input stream as follows: Variation Description get(); Extracts a single character from the stream and returns it. get( char*, int, char ); Extracts characters from the stream until either delim is found, the limit nCount is (more...)
还可以用 istream::getline()
eg. str = cin.getline(),具体如下:

istream& getline( char* pch, int nCount, char delim = '\n' );

istream& getline( unsigned char* puch, int nCount, char delim = '\n' );

istream& getline( signed char* psch, int nCount, char delim = '\n' );

Parameters

pch, puch, psch

A pointer to a character array.

nCount

The maximum number of characters to store, including the terminating NULL.

delim

The delimiter character (defaults to newline).
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
论坛导航 -> 华新鲜事 -> 求学狮城 | 返回上一页 | 本主题共有 3 篇文章,分 1 页, 当前显示第 1 页 | 回到顶部
<<始页  [1]  末页>>

请登录后回复:帐号   密码