Hello Experts,
This is a student question and I know you could use a list or some other keyed container but they haven't been introduced to the class so they aren't free game so to speak.
So...Given a struct And a vector of those structs is their a way to partially update just first_name and last_name. I can find an account using a simple bool function and find_if but trying to use that iterator causes an error.
Why is this const now?? Should I, Can I, cast const away in this context??
I can't use a wholesale copy because only part of the members of the struct are actually updated...
Can't use customer.at() since I don't have an index...
Some hints please...
DUH! answered my own question just looked at the code above I used a const_iterator should have used iterator instead. That fixed it.
Is there a better way to do this ??
JWEMAIL REMOVED BY MODERATOR.
This is a student question and I know you could use a list or some other keyed container but they haven't been introduced to the class so they aren't free game so to speak.
So...Given a struct And a vector of those structs is their a way to partially update just first_name and last_name. I can find an account using a simple bool function and find_if but trying to use that iterator causes an error.
Code:
struct customer{ string account; string first_name; string last_name; string address; string city; string state; string zip; string phone; double acct_balance; Date* date; }; vector<customer> customers; string t, id; typedef vector<customer>::const_iterator VCI; // Call a function to get account id from user // This works fine // Find the customer in the vector with the account id // This works fine t = id; transform( t.begin(), t.end(), t.begin(), toupper ); VCI f = find_if( customers.begin(), customers.end(), cust_eq(t)); // Create a little temporary to get new information customer* uCust = new( customer ); customer& cUpdate = *uCust; // Call some function to just get the first_name and last_name into cUpdate // This works fine... do_cust_name( cUpdate ); //but use the following code (*f).first_name = cUpdate.first_name; // produces main.cpp(249): error C2678: //binary '=' : no operator found which takes a left-hand //operand of type 'const std::string' (or there is no acceptable conversion)
I can't use a wholesale copy because only part of the members of the struct are actually updated...
Can't use customer.at() since I don't have an index...
Some hints please...
DUH! answered my own question just looked at the code above I used a const_iterator should have used iterator instead. That fixed it.
Is there a better way to do this ??
JWEMAIL REMOVED BY MODERATOR.
Comment