CPP学习笔记

-------------------------------------------------------
Accelerated C++

** Chapter 0 Getting Started **

--programming language
·core language
·standard library - #include directives - standard header

--iostream
The name iostream suggests support for sequential, or stream, input-output, rather than random-access or graphical input-output.

--namespace
standard library's output operator - "<<"
The name std::cout refers to the standard output stream.

--iostream
In a typical C++ implementation under a windowing operating system, std::cout will denote the window that the implementation associates with the program while it is running. Under such a system, the output written to std::cout will appear in the associated window.

--type & operand
std::cout, "Hello, world! " and std::endl are operands.
Every operand has a type.
std::cout has type std::ostream.

left-associative 左结合

--manipulator
std::endl is a manipulator, the key property of which is that writing a manipulator on a stream manipulates the stream, by doing something other than just write characters to it.

** Chapter 1 Working with strings **

--object vs. variable
An object is a part of the computer's memory that has a type.
The distinction between objects and variables is that it is possible to have objects that do not have names.
The limited lifetime of local variables is one reason that it is important to distinguish between variables and other object.

--string
the standard library says that every string object starts out with a value.

--I/O buffer
There are three events that cause the system to flush the buffer. First, the buffer might be full, in which case the library will flush it automatically. Second, the library might be asked to read from the standard input stream. In that case, the library immediately flushes the output buffer without waiting for the buffer to become full. The third occasion for flushing the buffer is when we explicitly say to do so.

--const
If we say that a variable is const, we must initialize it then and there, and we promise that the its value will not change after we have defined it.The value that we use to initialize the const variable need not itself be a constant.


--character literal
The type of a character literal is the build-in type char.

** Chapter 2 Looping and counting **

--increment operator
Incrementing an object is so common that a special notation for doing so is useful.

?? The idea of transforming a value into its immediate successor, in contrast with computing an arbitrary value, is so fundamental to abstract data structures that it deserves a special notation for that reason alone.

--loop invariant 循环不变式
Stating the invariant in a comment can make a while much easier to understand.

?? $2.3

--class scope
Like namespaces and blocks, classes define their own scopes.

--string::size_type - type-object
Whenever we need a local variable to contain the size of a string, we should use std::string::size_type as the type of that variable to ensure that the variable is capable of containing the number of characters in a string.

Nevertheless, whenever we define a variable that contains the size of a particular data structure, it is a good habit to use the type that the library defines as being appropriate for that specific purpose.

--for-statement
Asymmetric ranges are usually easier to use than symmetric ones because of an important property: A range of the form [m, n) has n - m elements, and a range of the form [m, n] has n - m + 1 elements.
This behavioral difference between asymmetric and symmetric ranges is particularly evident in the case of empty ranges: If we use asymmetric ranges, we can express an empty range as [n, n), in contrast to [n, n-1] for symmetric ranges. The possibility that the end of a range could ever be less than the beginning can cause no end of trouble in designing programs.

--C++ Programming Language
C++ inherits a rich set of operators from C, in addition, C++ programs can extend the core language by defining what it means to apply built-in operators to objects of class type.

--Data type
·size_t
Unsigned integral type (from <cstddef>) that can hold any object's size

·string::size_type
Unsigned integral type that can hold the size of any string

** Chapter 3 Working with batches of data **

--standard library
The <ios> header defines streamsize, which is the type that the input-output library uses to represent sizes.
The <iomanip> header defines the manipulator setprecision, which lets us say how many significant digits we want our output to contain.

--end-of-file signal
Ctrl+z Microsoft Windows
Ctrl+d Unix/Linux systems

--double vs. float
Even though it might seem that float is the appropriate type, it is almost always right to use double for floating-point computations.
We could have avoided this conversion by initializing sum to 0.0 instead of 0, but it makes no practical difference in this context: Any competent implementation will do the conversion during compilation, so there is no run-time overhead, and the result will be exactly the same.

--Initialization
Local variables of built-in type that are not explicitly initialized are undefined, which means that the variable's value consists of whatever random garbage already happens to occupy the memory in which the variable is created. It is illegal to do anything to an undefined value except to overwrite it with a valid value.

--set and reset cout's precision
Nevertheless, we believe that it is wise to reset cout's precision to what it was before we changed it.
// set precision to 3, return previous value
streamsize prec = cout.precision(3);
cout << "Your final grade is "
     << 0.2 * midterm + 0.4 * final + 0.4 * sum / count << endl;
// reset precision to its original value
cout.precision(prec);
However, we prefer to use the setprecision manipulator, because by doing so, we can minimize the part of the program in which the precision is set to an unusual value.

--condition
When used in a condition, the arithmetic value is converted to a bool: Nonzero values convert to true; zero values convert to false.

--cin as condition
There are several ways in which trying to read from a stream can be unsuccessful:

·We might have reached the end of the input file.
·We might have encountered input that is incompatible with the type of the variable that we are trying to read, such as might happen if we try to read an int and find something that isn't a number.
·The system might have detected a hardware failure on the input device.

--<algorithm> header
sort(v.begin(), v.end()) function rearrange the values in a container so that they are in nondecreasing order. The sort function moves the values of the container's elements aroud rather than creating a new container to hold the results.

--vector
The references to homework[mid] and v[index] show one way to access an element of a vector.

--size_type
Moreover, whenever ordinary integers and unsigned integers combine in an expression, the ordinary integer is converted to unsigned. In consequence, expressions such as homework.size() - 100 yield unsigned results, which means that they, too, cannot be less than zero—even if homework.size() < 100.

** Chapter 4 Organizing programs and data **

--The library facilities share several qualities: Each one
 1.Solves a particular kind of problem
 2.Is independent of most of the others
 3.Has a name

--Organizing programs and data
Like most programming languages, C++ offers two fundamental ways of organizing large programs:
 +--1.functions
 +--2.data structure s
 +--> class

--vector<T>::clear()
--istream::clear()
// read homework grades from an input stream into a vector<double>
istream& read_hw(istream& in, vector<double>& hw)
{
    if (in) {
        // get rid of previous contents
        hw.clear() ;

        // read homework grades
        double x;
        while (in >> x)
            hw.push_back(x);
   
        // clear the stream so that input will work for the next student
        in.clear();
    }
    return in;
}
Note that the clear member behaves completely differently for istream objects than it does for vector objects. For istream objects, it resets any error indications so that input can continue; for vector objects, it discards any contents that the vector might have had, leaving us with an empty vector again.

--A good rule of thumb好的经验
A good rule of thumb is to avoid more than one side effect in a single statement. Throwing an exception is a side effect, so a statement that might throw an exception should not cause any other side effects, particularly including input and output.

--函数命名
istream& read(istream& is, Student_info& s)
There is no ambiguity in naming this function read, because the type of its second parameter will tell us what we're reading.

 

-------------------------------------------------------
Programming Windows

--sz
string terminated with a zero

--win32 header files
windows.h
windef.h base type definition
 WINAPI - __stdcall
winnt.h  type for unicode support
 LPSTR PSTR
winbase.h kernel functions
 WinMain
winuser.h UI functions
wingdi.h GDI functions

--Hungarian Notation

 

-------------------------------------------------------
Visual Studio 6

--Open standard headers with <Find> in VS.

--Export a makefile in VS.

关于 阿里云盘CLI。仿 Linux shell 文件处理命令的阿里云盘命令行客户端,支持JavaScript插件,支持同步备份功能,支持相册批量下载。 特色 多平台支持, 支持 Windows, macOS, linux(x86/x64/arm), android, iOS 等 阿里云盘多用户支持 支持备份盘,资源库无缝切换 下载网盘内文件, 支持多个文件或目录下载, 支持断点续传和单文件并行下载。支持软链接(符号链接)文件。 上传本地文件, 支持多个文件或目录上传,支持排除指定文件夹/文件(正则表达式)功能。支持软链接(符号链接)文件。 同步备份功能支持备份本地文件到云盘,备份云盘文件到本地,双向同步备份保持本地文件和网盘文件同步。常用于嵌入式或者NAS等设备,支持docker镜像部署。 命令和文件路径输入支持Tab键自动补全,路径支持通配符匹配模式 支持JavaScript插件,你可以按照自己的需要定制上传/下载中关键步骤的行为,最大程度满足自己的个性化需求 支持共享相册的相关操作,支持批量下载相册所有普通照片、实况照片文件到本地 支持多用户联合下载功能,对下载速度有极致追求的用户可以尝试使用该选项。详情请查看文档多用户联合下载 如果大家有打算开通阿里云盘VIP会员,可以使用阿里云盘APP扫描下面的优惠推荐码进行开通。 注意:您需要开通【三方应用权益包】,这样使用本程序下载才能加速,否则下载无法提速。 Windows不第二步打开aliyunpan命令行程序,任何云盘命令都有类似如下日志输出 如何登出和下线客户端 阿里云盘单账户最多只允许同时登录 10 台设备 当出现这个提示:你账号已超出最大登录设备数量,请先下线一台设备,然后重启本应用,才可以继续使用 说明你的账号登录客户端已经超过数量,你需要先登出其他客户端才能继续使用,如下所示
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值