吸加加小白学习笔记(开个头)

听说FB很难找到Java组,能找到个C++的组就已经是烧高香了,赶紧来学C++以免干活太慢被terminate :(
实在不行再学Php吧,世界上最好的语言。

在命令行执行C程序

g++ -Wall -std=c++14 main.cpp

在网上执行 http://cpp.sh/

  std::cin >> favorite_number;
  std::count << "Amazing!! That's my favorite number tool !" << std:endl;

Build means : compiling, linking, create an executable file

Clean: remove all the object files.
变量
Variable: an abstraction for a memory location.
一定要预先声明变量
local variable

int age = 21;
int age (21);
int age {21};

Global variable
declared outside of main()
global variable 和 local variable相同的名字的话,能用local的先用local的

Character types

char, char16_t, char32_t, wchar_t
char middle_initial {'J'};

Integer types

signed and unsigned
short, int , long, long long
long long people_on_earth {7'600'000'000};

Floating point types;

float, 7
double 15
long double, 19
long double large_amount {2.7e120};

Boolean type

bool, 8 bit
bool game_over {false}

size and precision is often compiler-dependent

Casting

old style: (double) total
new style static_cast(total)

Array and vectors

int test_scores [5];
int test_scores [5] { 100, 95, 99, 87, 88};
int test_scores [5] {100, 98};
double hi_temperatures [365] {0};
int another_array[] {1, 2, 3, 4, 5};

test_scores[0]

比较
<=> three way comparision (C++20)
cout << boolalpha
cout << noboolapha

Structures of a C++ program

Variables and Constants
Arrays and Vectors
Strings in C++

unordered_map, 就是hash Map

control blocks

if (expression) 
    statement; 
else if (expression) 
    statement;
else 
  statement;

Switch statement

switch (integer_control_expr) {
  case expression_1 : 
      statement_1;
      break;
  case expression_2 : 
      statement_2;
      break;  
  default : 
    statement_default;
}

enum

enum Color {
  red, green, blue
};
switch (screen_color) {
  case red: 
     cout << "red";
     break;
  case green:
     cout << "green";
     break;
  default:
     cout << "should never execute";
}
enum Direction {
  left, right, up, down
};
Direction heading {left};

switch (letter_grade) {
  case 'a':
  case 'A':
     cout << "You need a 90 or above" << endl;
     break;
  case 'F':
     {
       statement_1;
     }
}

vector

vector nums {10, 20, 30, 40};

你可能感兴趣的:(吸加加小白学习笔记(开个头))