Foreach loop in C++ equivalent of C#

前端 未结 11 1747
礼貌的吻别
礼貌的吻别 2020-12-13 01:20

How would I convert this code to C++?

string[] strarr = {\"ram\",\"mohan\",\"sita\"};    
foreach(string str in strarr) {
  listbox.items.add(str);
}
         


        
11条回答
  •  旧巷少年郎
    2020-12-13 02:05

    using C++ 14:

    #include 
    #include 
    
    
    std::vector listbox;
    ...
    std::vector strarr {"ram","mohan","sita"};    
    for (const auto &str : strarr)
    {
        listbox.push_back(str);
    }
    

提交回复
热议问题