Chapter 1
compile & execute in command line
- g++ main.cpp(enable possible warnings,use g++ -Wall,e.g.Warnings All)
- g++ -o result main.cpp (in this way,generate execute file result;default a.out)
- ./a.out (‘/’use in linux & ‘'use in Win;to execute,we need to specify the current location:’./’)
- echo $?(to see status,e.g. return 0 or else)
iostream(Standard Library)
- #include
to use iostream - cin & cout define in the namespace std,so if without “using namespace std”,it will be std::cin、std:cout、std::endl
- cin»val cout«val,both of them return the lefthand,e.g. if input is an int,then cin»val succeed to read an int into val,then return true; so we can use while(cin»val) to keep record the input when input is an int.
comments
- single-line: // end with a new line
- paired: /* * / when span multiple lines, it is better to use * in every line
note:this type can’t appear inside again.it will result in mysterious errors.
flow of control
1.for(i=0;i<100;i++), when you want to iterate by 2 not 1,use while in which i=i+2;
class
- every class defines a type,likewise structure.The type name is class name.eg,we define a class Sales_item, and Sales_item item,means we define item as a object of type Sales_item,just like the built-in types.
- some languages just allow to define types that specify only what data make up the type; c++ allow operator as well as data.
others
- sum += val e.g.sum=sum+val;
- Headers from Standard Library are enclosed in <>;Other headers(we difine) are enclosed in “”.