How would I convert this code to C++?
string[] strarr = {\"ram\",\"mohan\",\"sita\"};
foreach(string str in strarr) {
listbox.items.add(str);
}
The simple form:
std::string data[] = {"ram","mohan","sita"};
std::for_each(data,data+3,std::bind1st(std::mem_fun(&Y::add), &(listbox.items)));
An example in action:
#include
#include
#include
#include
class Y
{
public:
void add(std::string value)
{
std::cout << "Got(" << value << ")\n";
}
};
class X
{
public:
Y items;
};
int main()
{
X listbox;
std::string data[] = {"ram","mohan","sita"};
std::for_each(data,data+3,std::bind1st(std::mem_fun(&Y::add), &(listbox.items)));
}