Code:
if (containsString(filestreamInBuffer_ca, "=")) { //last enumerator line contains the '=' character
cout<< "The last enumerator of the enum has an assigned value." <<endl;
currentEnumeratorHasAssignedValue_b = true;
//get numerical value of current enumerator:
currentEnumeratorValue_s = stripString(strippedStr_s.c_str(), '=', ','); //we now have the last enumerator's assigned value in a string
istringstream currentEnumeratorValue_iss(currentEnumeratorValue_s);
currentEnumeratorValue_iss>> currentEnumeratorValue_i;
cout<< "currentEnumeratorValue_i is: " << currentEnumeratorValue_i <<endl;
enumeratorValues_v_i.push_back(currentEnumeratorValue_i);
//get name of enumerator:
firstCharOfEnumeratorName_c = filestreamInBuffer_ca[0]; //get first character of line read from file
//strip the line read from the first char of the enum value name to the '=' character, inclusive:
strippedStr_s = stripString(filestreamInBuffer_ca, firstCharOfEnumeratorName_c, '=', inclusive);
lastCharIndex_ui = strippedStr_s.size() - 1; //get index of last character of stripped string
strippedStr_s.erase(lastCharIndex_ui, 1); //erase last character of stripped string (the '=' character)
currentEnumeratorName_s = strippedStr_s; //we now have the last enumerator's name
cout<< "currentEnumeratorName_s is: " << currentEnumeratorName_s <<endl;
enumeratorNames_v_s.push_back(currentEnumeratorName_s);
enumeratorsCounter_ui++; //increment the enumerators counter
if (currentEnumeratorHasAssignedValue_b) {
enumeratorsMap_m_is[currentEnumeratorValue_i] = currentEnumeratorName_s;
cout<< "enumeratorsMap_m_is.find(" << currentEnumeratorValue_i << ")->second is: "
<< enumeratorsMap_m_is.find(currentEnumeratorValue_i)->second <<endl;
currentEnumeratorHasAssignedValue_b = false; //reset it to false
}
else {
if ((enumeratorsCounter_ui != 1) && (currentEnumeratorValue_i != 0)) {
currentEnumeratorValue_i++;
}
else {
if (currentEnumeratorValue_i != 0) { //for some bizarre reason...
currentEnumeratorValue_i = 0; //set it to 0 just to be safe
}
}
enumeratorsMap_m_is[currentEnumeratorValue_i] = currentEnumeratorName_s;
}
}
The debug output statements show that the first enumerator in an enum read from file has the value 1 (which is correct). The one after that has a value of 2, but it outputs 1. That is why I suspected the istringstream >> operator could not insert a variable which already has a value.
Here is the enum that its reading:
Code:
enum Work {
hard = 1,
lazy = 2
};
CodeMonkey: Your code wouldn't compile: C++ code - 21 lines - codepad
Stop monkeying around!