Hi, I'm having some problems with this bit of code. I need to randomly open some files that have numbers as their filenames. i came up with this snippet to be able to open them from numbers 0 to 99. The code should randomly pick a number and try to open a file with that name, if the file does not exist, it lowers the range of numbers it can pick until reaching 10. I ran this on Ubuntu and it worked perfectly, but when I switch to Windows the loop never ends. If instead of using a random filename I use, for example filename="Synthesis//2.txt"; the program runs fine. i don't know why the code works on Ubuntu but not in Windows Vista. Any help is apreciated.
std::string Synthesis::itoa(int number)
{
std::stringstream word;
std::string output;
word<<number;
word>>output;
return output;
}
int Synthesis::Load( int Level){
int disponible=100; // las sintesis disponibles del 0 al 99 en ese level
ifstream tempsynth;
string filename;
int SynthNumber;
do {
SynthNumber = rand() % (disponible)+ Level*100;
filename="Synthesis//"+itoa(SynthNumber)+".txt"; //itoa is a custom funtion that return a string
Log<<filename.c_str()<<"\n"; //this prints the filename into a file
tempsynth.open(filename.c_str());//,ios::binary);
if (!tempsynth && disponible>=10)
disponible=disponible-3; //como no van a haber 100 sintesis se baja la busqueda hasta que hallan
}
while (!tempsynth );