C++Primer(英語第5版)日記を読む-20200411

3102 ワード

Chapter 1: Getting Start
前編に続く.今日はPrimerを読み続けた翌日ですが、このブログを見たあなたも一緒に頑張ってほしいです!生活が苦しくても疲れても勉強しなければならないでしょう.日記はまずC++熟練度を習得し、系統的に学ぶことにある.主にいくつかの問題と知識点を記録しましょう.できるだけ簡略化します.中国語と英語を混合して、用語の一致と便利さを維持します.
Note 1.4 Using
  • “::” is called the scope operator
  • namespace is to avoid inadvertent collisions between the names we define
  • Example: for std::endl, std is the namespace while endl is name in that namespace.

  • Note 1.5 Comments
    注釈は省略されているでしょうが、もう0202年も経っているので、C++で注釈を使わない人はいないはずです.
    Note 1.6 Flow of control
    これはすべて最も基礎的なものです.いいえ、コードができますか?すばやくかすめることができます.
    while loop:基本サイクルは言わない
    while (condition)
        statement

    ++val; <=> val = val + 1;
    for statement
    int sum = 0;
    for (int i = -100; i <= 100; ++i)
        sum += i;

    Example: read until end of file
    #include 
    
    int main() {
        int value = 0;
        int sum = 0;
        while (std:: cin >> value) {
            sum += value;
        }
        std:: cout << sum;
        return 0;
    }

    覚えておいてstd::cin>>valueはstd::cin、彼はistreamです.だから、ここのconditionはstd::cin,which becomes invalid when we hit end-of-file or encounters an invalid input,such as reading a value that is not an integer.
    常用:windows EOFはctrl+z(powershellでは役に立たないようです)、unix EOFはctrl+d(これは大丈夫です)
    if statement:兄弟、if文もできないので、家に帰って畑を植えることができます.
    Note 1.6: Three types of error: syntex, type, declaration
    これらのerrorは普段頭を上げて頭を下げないで、ここでシステムを整理します.これらのerrorがどのような状況で現れたのか、多くの人が食べられないかもしれません.
  • syntex error: grammatical error in C++ language. (e.g: miss of operator, etc.)
  • type error: each item of data in C++ has an asscoiated type. pass a type to a function that does not expects that type may trigger type error.
  • declaration error: 

  • Note 1.7: Classes
    Classはみんな使っていますが、はっきり言うのは難しいです.
  • C++ defines our own data structures by defining a class
  • A class defines a type along with a collection of operations that are related to that type.

  • ヘッダファイルは何ですか?アプリケーション面から、ヘッダファイルを明確に説明することができます.
  • ライブラリを使用して、私たちのincludeヘッダファイル:To use a library facility、we must include the associated header.
  • だから、自分たちのアプリケーションを定義するには、ヘッダファイルを定義します:To define our own applications,we have to use headers.
  • Header file names are derived from the name of a class defined in that header by convention.
  • We usually have a suffix of .h or .hpp, .H or .hxx.

  • Each class defines a type. The type name is the same as the name of the class.
    メンバー関数
  • Use the dot operator (".") to call a member function : left oprend (an object of class type) and the right-hand operand must name a member of that type. 

  • Call operator("(")):カッコで方程式を呼び出す専門用語を見てみましょう
  • We use dot operator to access a member function
  • We call a function by call operator.
  • The call operator is a pair of parenetheses that enclose a (possibly empty) list of arguments.

  • 今日はこれで筆を置き,明日また戦う.具体的なclassの実現はこの章ではないはずだ.