2012年5月1日 星期二

case placement in switch control block


#include <iostream>
using namespace std;
int main(){
    for(int i = 0 ; i<=2; i++){
        cout << "i = " << i << "\n";
        switch(i){
            case 0:
                cout << "case 0 touched\n";
            default:
                cout << "case default touched\n";
            case 1:
                cout << "case 1 touched\n";
        }
    }
}


output:


i = 0
case 0 touched
case default touched
case 1 touched
i = 1
case 1 touched
i = 2
case default touched
case 1 touched


Usage of const in C++

http://duramecho.com/ComputerInformation/WhyHowCppConst.html

1. Variables declared with ‘const’ added become constants and cannot be altered by the program.

2. One has to initialise it immediately in the constructor because, of course, one cannot set the value later as that would be altering it.


3. function returned value, function parameter passing, function itself
const int*const Method3(const int*const&)const;
where the 5 uses ‘const’ respectively mean that the variable pointed to by the returned pointer & the returned pointer itself won’t be alterable and that the method does not alter the variable pointed to by the given pointer, the given pointer itself & the object of which it is a method!.

2012年4月24日 星期二

C++_Grocery


*******CLASSES*******
<iostream>
        cin, cout, flush, '\a', '\b', '\t', '\n', endl, >> (search ignoring whitespace, fetch until unmatched.), <<
<iomanip>
        setw(2), setprecision(16), setiosflags(ios::left/right/fixed), resetiosflags(ios::left/right/fixed)
<fstream>
        ofstream ofsname("filename"), ofsname<<"stream to write", ifstream ifsname("filename"), getline(ifsname,linestringread)
        , eof(), is_open();
<cmath>
        fabs(double d), sqrt(double d)
<ctime>
        time_t, time(NULL) => time_t, ctime(&t) => string formatted time, difftime(t1, t2) => integer seconds,
<string>
        st.find('\n') => index, string::npos, st.substr(0,5) => string, stringstream
<exception>
        class exception, exception.what()



2010年10月16日 星期六

大雨中的追浪

這一道浪來了, 看準了, 拚命向前划…
感受它向前推進的動力, 我明白這次追到了….
這個速度, 這個熟悉的速度與推進力…

天空是陰的, 海風吹得滂沱大雨也不得不脫離自由落體的定律…
大雨落在浪板上,珍珠般的銀白
好像一時間, 那個美,那個閃耀著光芒的…美鑚…
"存在"激動著, 靜靜的, 享受著, 一個"無人"趴在浪板上, 這永恆的片刻….