Foreach loop in C++ equivalent of C#

前端 未结 11 1741
礼貌的吻别
礼貌的吻别 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 01:58

    Something like:

    const char* strarr = {"ram","mohan","sita", 0L};
    
    for(int i = 0; strarr[i]; ++i)
    {
      listbox.items.add(strarr[i]);
    }
    

    Also works for standard C. Not sure in C++ how to detect the end of the strarr without having a null element, but the above should work.

提交回复
热议问题