2010-11-22 61 views
0
void Record::Update() { 

string choice; 

cout << "Enter ID: " << endl; 
cin >> IDValue; 
    for(Itr = List.begin() ; Itr !=List.end() ; Itr+) { 
    if(Itr->GetID() == IDValue) 
    { 
    cout << Transit->GetID() << endl; 
    cout << "Would you like to set Name ? (y/n) :"; 
    cin >> choice; 
    if (choice == 'y') 
     cin >> strName; 
    Itr->SetName(strName); 

    cout << Itr->GetName() << endl; 
    cout << Itr->GetLocation() << endl; 
    } 

    } 
} 

该函数通过其唯一的ID号查找记录。每个新记录都有一个ID号码。如果我输入ID 2,则该功能会显示ID为2的记录。如何修改记录的某个属性?在这种情况下,它的位置。向量中的更新值

+2

谁知道。这个容器中存储了哪些类型的对象,并允许您修改位置? – 2010-11-22 02:24:58

+0

你有增变器方法吗? 'Transit-> SetID(9)'会起作用吗? – 2010-11-22 02:25:49

+0

我讨厌它,当你创建一个新的帐户,每次你问问题:* http://stackoverflow.com/questions/3860271 * http://stackoverflow.com/questions/4108853 – 2010-11-22 02:38:47

回答

0
void RecordList::UpdateLocation() { 

    int IDValue; 
    char* strName; 
    char opt; 

    cout << "Enter ID number to update: " << endl; 
    cin >> IDValue; 
     for(Transit = List.begin() ; Transit !=List.end() ; Transit++) { 
     if(Transit->GetID() == IDValue) 
     { 
     cout << Transit->GetID() << endl; 
     cout << "Would you like to set Name ? (y/n) :"; 
     cin >> opt; 
     if (opt == 'y') 
      cin >> strName; 
     Transit->SetName(strName); 

     cout << Transit->GetName() << endl; 
     cout << Transit->GetLocation() << endl; 
     } 

    } 
} 
+0

谢谢,这比我想象的更容易是。我实际上只是创建了一个新的局部变量,然后使用Transit-> SetName(strName)输入它; – chief 2010-11-22 03:53:24

0

您将Transit对象编程为使用setXXX()方法,然后调用该方法。迭代器的工作主要是指针,所以你可以用setter方法改变一个类变量。