1

我如何设置以下内容:

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"));

不是专门写所有东西,而是像 1-9 这样的东西,所以这个数字数组包含 1-9 的所有内容,不包括 0 。

谢谢

4

2 回答 2

2
// 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]);
于 2012-08-07T11:02:19.760 回答
0

如果我理解正确,你希望数组只接受一组数据吗?如果你,你可以创建一个这样的类:

class MyArray
{
    //your accepted data will be stored in this vector.
    std::vector<int> data;

    //the acceptable values will be stored in this set. 
    std::set<int> acceptable;

    public:
        MyArray()
        {
            // in the constructor we fill the set.
            for(int i=0; i<=10; i++)
                acceptable.insert(i);
        }
        void add(int item)
        {
            // if the set contains the item you want to insert, then insert it
            if(acceptable.find(item) != acceptable.end())
            {
                data.push_back(item);
                std::cout<<"Added";
            }
            // else throw error or simply don't add it.
            else
            {
                std::cout<<"Not acceptable";
            }
        }
};

如果我完全误解了你,那么对不起!只要告诉我,如果它无关紧要,我会删除答案!

于 2012-08-06T10:43:57.243 回答