Search code examples
c++wxwidgets

c++-setting an array that accepts a list of values


How do i set the following :

wxArrayString numberArray;
numberArray.Add(wxT("1"));
numberArray.Add(wxT("2"));
numberArray.Add(wxT("3"));
numberArray.Add(wxT("4"));
numberArray.Add(wxT("5"));
numberArray.Add(wxT("6"));
numberArray.Add(wxT("7"));
numberArray.Add(wxT("8"));
numberArray.Add(wxT("9"));

not as writing everything specificlly but something like 1-9 so that this number array has everything from 1-9 , excluding 0 .

Thanks


Solution

  • // Add numbers 1-9 to numberArray
    wxArrayString numberArray;
    
    for (size_t i = 1; i <= 9; ++i)
        numberArray.Add(wxString::Format(wxT("%d"), i));
    
    // Display content of numberArray
    for (size_t i = 0; i < numberArray.size(); ++i)
        wxLogDebug(numberArray[i]);