现在的位置: 首页 > 综合 > 正文

C++的新语法

2013年09月26日 ⁄ 综合 ⁄ 共 272字 ⁄ 字号 评论关闭

http://www.cprogramming.com/c++11/c++11-ranged-for-loop.html

有一个数组 int a[5] = {1, 2, 3, 4, 5};

以前要遍历方法如下:

    for (int i = 0; i < sizeof(a); i++)
    {
        std::cout << a[i] << std::endl;
    }

现在在C++ extension 11中新方法如下:

    for (int i: a) {
        std::cout << i << std::endl;
    }

关于其它新功能:http://www.cprogramming.com/c++11/what-is-c++0x.html

抱歉!评论已关闭.