//***************************************************************************
int studentNum(string level)
{
int name;
switch (level)
{
case"Freshman":
name = 0;
break;
case"Sophomore":
name = 1;
break;
case"Junior":
name = 2;
break;
case"Senior":
name = 3;
}
return name;
}
//***************************************************************************
void newSorted(ofstream& outCreditData, string idNum[], string classLevel[], int& cnt)
{
int i;
int temp;
for(int i = 0; i < cnt; i++)
{
temp = studentNum(classLevel);
outCreditData << idNum[i] << " " << classLevel[i] << endl;
}
outCreditData.close();
return;
}
classLevel[] contains strings like "Senior, sophomore, Junior, etc.
I basically, want to convert this string value to an int, so I can write the int value to my text file. Thank you very much.
switch statements can only be used with integral types (int, char, long..). So strings don't work. Rewriting studentNum using if-else chains is the only way, or using an std::map but that might be overkill for the situation.
But besides the switch statement,
temp = studentNum(classLevel);
classLevel is an array of std::strings, but your studentNum function expects a string. Perhaps you meant to pass classLevel[i]?