size_tの使用例@C++

2611 ワード

中国語と英語の対照的なバージョンを説明するのにいいです.
#include 
#include 
using namespace std;


size_t count_calls()
{
    static size_t ctr = 0;  //                   ,       
    return ++ctr;
}


int main()
{
    for (size_t i = 0; i != 10; i++)
        cout << count_calls() << endl;
    size_t a;
    //        B,                   32, 64
    cout << "a       " << typeid(a).name() << "    :" << sizeof(a) * 8 << " "<< endl;

    int b;
    unsigned int c;
    cout << "b       " << typeid(a).name() << "    :" << sizeof(b) * 8 << " " << endl;
    cout << "c       " << typeid(b).name() << "    :" << sizeof(c) * 8 << " " << endl;
    /*
    a       unsigned __int64    :64 
    b       unsigned __int64    :32 
    c       int    :32 
        , int   unsigned int          ,                    
         int   ,   size_t             
      size_t            。  size_t                           ,
    size_t              。
    */
    return  0;
}