2010-11-22 46 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方法改變一個類變量。