J
Joe Laughlin
I have this snippet of code. Let me know if I need to give more for
feedback:
typedef std::map<const char*, float> AttitudeRecord;
// player_info.GetAttitude should return an AttitudeRecord with
// key: roll value: 34
// key: pitch value: 598
// key: attitude value: 34
AttitudeRecord atttiude = player_info.GetAttitude();
AttitudeRecord::iterator iter;
iter = attitude.find("pitch");
// This prints out a completely wrong value! Why?
std::cout << "Value of pitch: " << attitude->second;
// This loop prints what seems to be the correct values
for (iter = attitude.begin(); iter != attitude.end(); ++iter)
{
std::cout << "\nKey: " << iter->first << " Value: " << iter->second;
}
Output:
Value of pitch: 3893.33 (Wrong!)
Key: roll Value: 34
Key: pitch Value: 598
Key: heading Value: 34
What I really want to do is easily get to the value of a specific key. But
I can't seem to find a way to do it.
feedback:
typedef std::map<const char*, float> AttitudeRecord;
// player_info.GetAttitude should return an AttitudeRecord with
// key: roll value: 34
// key: pitch value: 598
// key: attitude value: 34
AttitudeRecord atttiude = player_info.GetAttitude();
AttitudeRecord::iterator iter;
iter = attitude.find("pitch");
// This prints out a completely wrong value! Why?
std::cout << "Value of pitch: " << attitude->second;
// This loop prints what seems to be the correct values
for (iter = attitude.begin(); iter != attitude.end(); ++iter)
{
std::cout << "\nKey: " << iter->first << " Value: " << iter->second;
}
Output:
Value of pitch: 3893.33 (Wrong!)
Key: roll Value: 34
Key: pitch Value: 598
Key: heading Value: 34
What I really want to do is easily get to the value of a specific key. But
I can't seem to find a way to do it.