C++ initializer_list 简单测试

#include <iostream>
#include <string>

static void  show_msg(std::initializer_list<std::string> str_list)
{
    for (auto beg = str_list.begin(); beg != str_list.end(); ++beg)
    {
        std::cout << *beg << std::endl;
    }
}

int main()
{
    show_msg({ "hello", "world", "good", "morning" });
    return EXIT_SUCCESS;
}

输出:

hello
world
good
morning
posted @ 2024-07-18 13:00  double64  阅读(1)  评论(0编辑  收藏  举报