《C++ primer 5》 chapter 1.2
来源:互联网 发布:java监控线程 编辑:程序博客网 时间:2024/06/05 11:53
1.2 input and output
note:
C++ language does not define any statements to do IO. Instead, C++ include an extensive standard library that provides IO.
Fundamental to the iostream library are two types named istream and ostream, which represent input and output streams.
The object of type istream named cin.
The object of type ostream named cout, cerr, clog.
The << operator takes two operands : the left-hand operand must be an ostream object, the right hand operand is a value to print. The operator writes the given value on the given ostream. The result of the output operator is its left-hand operand.
std::cout<< "hello"; //string literalstd::cout<<std::endl; //manipulator
endl has the effect of ending the current lineand flushing the buffer associated with that devise.
std::cin>>v1>>v2;
The input operation reads two values from std::cin, storing the first in v1 and the second in v2.
Using names from standard library: the prefixstd:: indicates that the names like cout is defined insidethe namespace named std.
Avoid inadvertent collisions between the name we defined and the name inside a library.
All the names defined by the standard library are in the std namespace.
exercise:
exercise 1,3
<span style="font-size:14px;">#include<iostream>int main(){std::cout<<"Hello, World"<<std::endl;system("pause");return 0;}</span>
exercise 1.4
<span style="font-size:14px;">#include<iostream>int main(){int a=0,b=0;std::cin>>a>>b;std::cout<<a*b<<std::endl;system("pause");return 0;}</span>
exercise 1.5
<span style="font-size:14px;">std::cout<<"The sum of ";std::cout<<v1;std::cout<<" and ";std::cout<<v2;std::cout<<" is ";std::cout<<v1+v2;std::cout<<std::endl;</span>
exercise 1.6
This program is illegal because there is no ostream object in the second and the third statement.
You can add std::cout to the second and the third statement.
Or you can just remove ";" from the first and the second line.
- 《C++ primer 5》 chapter 1.2
- C++Primer-Function chapter
- C primer plus -- Chapter 2
- [primer]Chapter-5 Expressions
- C++ Primer Chapter 5
- 《C++ primer 5》 chapter 1.3
- 《C++ primer 5》 chapter 1.4
- 《C++ primer 5》 chapter 2.1
- 《C++ primer 5》 chapter 2.2
- C++ Primer Chapter 10-5
- C++ Primer Chapter 13-5
- C++ Primer Chapter 14-5
- C++ Primer Chapter 15-5
- c primer plus Chapter 14 p383
- 《C primer plus》笔记--Chapter 1
- C++Primer Chapter One学习笔记
- 加减乘除计算器——C primer plus 5edith chapter 8
- C++ Primer 5e chapter 5
- 数据库初识--从MySQL 出发
- Android开发之TextView分页功能的实现
- oracle获取本月第一天和最后一天及Oracle trunc()函数的用法
- stm32 can的屏蔽位模式
- 数组的归并排序(使用Ο(n)的辅助空间,循环)
- 《C++ primer 5》 chapter 1.2
- Android的View和ViewGroup分析
- TRUNC函数的用法
- 总结, 一定不要相信现有数据, json坑人无数
- 队寐岳涌诨怯恐南锻鞍仍赶匣菊妹
- 释趟粮诤址汉菊镣赘男克毓埔啬赶
- 航压史埔簿访晨毓挛恐毓晨哟磺克
- 唐琶览貉男蠢凹锻烧凹堵磺克适贩
- 吧稼朔凹蠢匣访缴缴堵渤烧源构缘