I guess Dev-cpp/g++ doesn't like my case statement. Any ideas?
Thanks ahead of time.
Code:
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
class Hanzi
{ public:
Hanzi() { };
Hanzi(const Hanzi &) { };
~Hanzi() { };
int GetRadCat() { return itsRadCat; };
void SetRadCat(int rc) { itsRadCat = rc - 1; }; //1 subtracted for use in array
void SetRad(int rc) { };
void GetRad(int rc) { };
void SetROS(int theRest) { ros = theRest; }; // ros is rest of strokes
void DisplayRads(int r); // r is radical category
void DisplayRads(int radcat, int roStr);
private:
int itsRadCat,
nrs, // number of radical strokes
radChoice, // which radical you choose
ros; // "rest of strokes"...number of strokes in the rest of the char
};
void Hanzi::DisplayRads(int r)
{
switch(r)
{ case 12: ifstream infile("rad12.txt"); break;
case 11: ifstream infile("rad11.txt"); break;
case 10: ifstream infile("rad10.txt"); break;
case 9: ifstream infile("rad9.txt"); break;
case 8: ifstream infile("rad8.txt"); break;
case 7: ifstream infile("rad7.txt"); break;
case 6: ifstream infile("rad6.txt"); break;
case 5: ifstream infile("rad5.txt"); break;
case 4: ifstream infile("rad4.txt"); break;
case 3: ifstream infile("rad3.txt"); break;
case 2: ifstream infile("rad2.txt"); break;
case 1: ifstream infile("rad1.txt"); break;
default: cout << "Invalid choice!" ; break;
char arry[120];
for(int a=0; a<120; a++)
{ infile.getline(arry[a], 120, '\n');
}
for(int b=0; b<120; b++)
{ cout << "\t[" << b+1 << "] " << arry[b] << endl;
}
}
int main()
{ Hanzi thisHanzi;
cout << "How many strokes are there in the radical? ";
cin >> nrs;
thisHanzi.SetRadCat(nrs);
cout << "The radical category is " << thisHanzi.GetRadCat() << "\n";
cout << "Here are the radicals in radical category "
<< thisHanzi.GetRadCat() << ". 1 subtracted for use with array.\n";
thisHanzi.DisplayRads(itsRadCat);
cout << "Which of these is the radical you need?\n";
cin >> radChoice;
//thisHanzi.SetRad(radChoice);
//cout << "You chose this radical: " << thisHanzi.GetRad(radChoice);
cout << "How many strokes are there in the rest of the character? ";
int theRest;
cin >> theRest;
//thisHanzi.SetROS(theRest);
cout << "Here are the characters with that radical and that number of strokes remaining: \n";
//thisHanzi.DisplayRads(radChoice, ros);
Compiler: Default compiler
Executing g++.exe...
g++.exe "D:\HanziClass.cpp" -o "D:\HanziClass.exe" -I"C:\DEVC\include" -I"C:\DEVC\include" -L"C:\DEVC\lib"
D:\HanziClass.cpp: In method `void Hanzi::DisplayRads(int)':
D:\HanziClass.cpp:30: case label `11' within scope of cleanup or variable array
D:\HanziClass.cpp:29: warning: destructor needed for `class ifstream infile'
D:\HanziClass.cpp:30: warning: where case label appears here
Read something in one of my C++ books about not using a floating point somethin or other in a case statement. Can anyone clarify that for me?
Thanks,
Swaine777