I am currently working on a cricket scoreboard project. And I would like to keep the teams data in a single folder.
I tried a lot of things but I wasn't able to open the file kept in a different folder.
Here is a snippet of my code:
if(strcmp(TeamName,"Australia")==0||strcmp(TeamName,"australia")==0)
rf.open("/teams/australia.dat",ios::in|ios::binary);
else if(strcmp(TeamName,"india")==0||strcmp(TeamName,"India")==0)
rf.open("india.dat",ios::in|ios::binary);
else if(strcmp(TeamName,"England")==0||strcmp(TeamName,"england")==0)
rf.open("england.dat",ios::in|ios::binary);
else if(strcmp(TeamName,"pakistan")==0||strcmp(TeamName,"Pakistan")==0)
rf.open("pakistan.dat",ios::in|ios::binary);
else if(rf)
{
cout<<"\n\t\t FILE NOT FOUND";
return ;
}
if(!rf.is_open())
cerr<<"\n\n\t\tFile not open!";
rf.read((char*)&rec,sizeof(rec));
cout<<"\n\t\t Team "<<TeamName;
while(!rf.eof())
{
cout<<"\n\t\t "<<rec.PlayerNumber<<"\t"<<rec.PlayerName;
rf.read((char*)&rec,sizeof(rec));
}
There is no compile time error. The file just fails to open at runtime. if(!rf.is_open()) cerr<<"\n\n\t\tFile not open!"; This error message is printed on the console and it goes in infinite loop.
How do I open it using file.open();