知识库

C++语言开发示例:05. foreach循环

2025-02-01 20:27:54 李腾 1 次阅读

forrange.cpp

#include <iostream>

int main()
{
    double prices[5] = {4.99, 10.99, 6.87, 7.99, 8.49};
    for (double x : prices)
    {
        std::cout << x << " ";
    }
    std::cout << std::endl;

    for (double &x : prices)
    {
        x = 1;
    }
    for (double x : prices)
    {
        std::cout << x << " ";
    }
    std::cout << std::endl;
}
转载请注明转自www.hylab.cn,原文地址:C++语言开发示例:05. foreach循环

评论 (0)

登录后发表评论

暂无评论,快来发表第一条评论吧!