2015-01-28 4 views
0
class item 
{ 
private: 
    std::string name; 
    double price; 
    int quantity; 

public: 
    void item(); 
    void setName(string itemName); 
    std::string getName(); 
    void setPrice(double itemPrice); 
    double getPrice(); 
    void setQuantity(int itemQuantity); 
    int getQuantity(); 
}; 

class list 
{ 
private: 
    std::vector<std::vector<item>> notepad; 

public: 
    bool isEmpty(); 
    void addList(); 
    void printLists(bool printTotalPrice); 
    void addItem(); 
    void removeItem(); 
    void editItem(); 
    void importList(ifstream& iFile); 
    void exportList(ofstream& oFile); 
}; 

여기 내가 문제가되는 곳입니다. 내 function list :: addItem()에 대해서 사용자가 문자열을 입력하여 메모장 벡터의 첫 번째 행 요소 만 검색하여 일치하는 것을 찾고 싶습니다. 이 같은벡터 벡터 내에서 클래스의 멤버에 액세스

뭔가 ...

  for (int i = 0; i < notepad.size(); ++i) 
      if (user's entered string) == first element of 'i'th vector.getName() 

... 일치

내가 이것을 할 수있는 방법에 대한 아이디어를 발견?

답변

0
if (user_entered_string == notepad[i][0].getName()) 

[i]notepad에서 'i 번째 벡터를 가져옵니다.

[0]은 첫 번째 결과가 item입니다.

.getName()이 호출됩니다.