您的位置:首页 > 编程语言 > PHP开发

A First Look At Input/Output

2012-10-22 21:25 330 查看
1.stream

A stream is a sequence of characters intended to be read from or written to an I/O device of some kind. The term "stream" is intended to suggest that the characters
are generated, or consumed, sequentially over time.

2.standard input and output objects

The library defines four IO objects:

cin
(standard input)

cout
(standard output)

cerr
(standard error)

clog
(for general information about the execution of the program)

3.#include preprocessor directive

The
#include directive must be written on a single line - the name of the header and the#include must appear on the same line.

4. output operator <<

The output operator writes its right-hand operand to the ostream that is its left-hand operand.

The result is the value of its left-hand operand. This fact allows us to chain together output requests.For example,

cout<<"enter two numbers:";

cout<<endl;
=
(cout<<"enter two numbers:")<<endl;
=
cout<<"enter two numbers:"<<endl;

5.input operator >>

It reads from its
istream operand and stores the value it read in its right-hand operand.

The input operator returns its left-hand operand as its result. Thus, we can combine a sequence of input requests into a single statement. For example,

cin>>v1;

cin>>v2;
=
cin>>v1>>v2;

如果输入的是:2,8,那么执行中cin的流字符如下:

cin>>v1;
//cin(2,8)

cin>>v2;
//cin(8)

第一句执行完成后,流字符中的2就被consumed了。

6.The iostream library defines versions of the input and output operators that accept all of the built-in

types.

That's the concept behind the following statement:

cout<<"the sum of "<<v1<<"and"<<v2<<"is "<<v1+v2<<endl;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: