Ok, I've posted about this before but this one is for after I tried something someone suggested about replacing a big ol' case statement with this ostringstream to help reduce the code a lot. It makes sense but the compiler doesn't seem to like it so I guess I'm doing it wrong. I'm trying to make a file name out of an int and a piece of text...a filename that I can actually use (i.e. open and read from). How do I make it use it correctly after I make the filename with ostringstream?
Stink, I don't have the error messages from the compiler atm but I'll be back to post those soon. Sorry. Thanks for any advice you could throw my way.
Swaine777
Code:
void Hanzi::DisplayRads(int r)
{
ifstream infile;
ostringstream name;
int i = r;
name << "rad" << i << ".txt" << flush;
cout << "\nname is " << name.str() << endl;
string name2 = name.str();
cout << name2 << endl;
infile.open(name2);
if(!infile)
cout << "Aw, bummer, the file didn't open!\n";
else
{ char arry[120];
int count = -1;
for(int a=0; a<1; a++)
{ infile.getline(arry[++count], 80, '\n');
}
for(int b=0; b<60; b++)
{ if((b=0) || (b%2 == 0))
cout << b+1 << ". " << arry[b];
else
cout << "\t" << b+1 << ". " << arry[b] << endl;
}
} //if(infile) else
infile.close();
} //Hanzi::DisplayRads