初学C++ 之 auto关键字(IDE:VS2013)

/*使用auto关键字,需要先赋初值,auto关键字是会根据初值来判断类型*/
    auto i = 5;
    auto j = 10;
    cout << "auto i = 5" << "\ti type:" << typeid(i).name() << endl << "auto j = 10" << "\tj type:" << typeid(j).name() << endl;
    cout << "i + j = " << i + j << endl;

    auto a = "Hello World!";
    cout << "auto a = Hello World!" << endl;
    cout << "a type:" << typeid(a).name() << endl;

    auto b = false;
    cout << "auto b = false" << endl;
    cout << "b type:" << typeid(b).name() << endl;

 

posted @ 2016-09-29 10:30  blackday  阅读(782)  评论(0编辑  收藏  举报