2012-08-06 3 views
1

의 목록을 받아 배열 설정 :C++ - 나는 다음과 같은 설정하려면 어떻게 값

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처럼 specificlly 모든하지만 뭔가를 작성하는 것은 그래서이 숫자 배열은 1-9에서 모든 것을 가지고 0을 제외하고

감사

+0

이 코드는 유니 코드 빌드, 비 유니 코드 또는 둘 모두입니까? –

답변

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

내가 완전히 당신을 오해한다면, 미안 해요! 저에게 말해주십시오. 만약 그것이 무의미하다면 나는 대답을 제거합니다!

+0

헤더와 함께 작성하십시오 –

+0

별도의 헤더/cpp 버전에서이 코드가 필요합니까? –