c++ note some detail

cin>> will check digit or other string automatically  but cin.get  don't check it

#include<iostream>

using namespace std;

int main()
{
  char one_char,decimal_point,digit1,digit2;
  long dollars;
  bool negative;
  cin>>one_char;
  if(one_char == '-')
  {
     negative = true;
     cin >> one_char;
  }
  else
  {
     negative=false;
  }

  cin>>dollars>>decimal_point>>digit1>>digit2;

  cout<< dollars <<" "<<decimal_point <<"  "<<digit1<< "   " <<digit2<<endl;
}

static_cast<int>(v_char)-static_cast<int>('0');                       --return cast char to int

operator + or - or other applay a class instance+20  must be let os known how the 20 add the instance  
first check operator  fail then  call instructor implicitly

ostream & operator<<(ostream & outs ,const class& cs)                 

big three  copy constructor 、operator equal and destructor

unnamed namespace {}   is local to compilation unit.   global namespace

版权声明:本文为sql_xep原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。