hi, i was having trouble with this code opening the file:
void loadstats()
{
fstream input;
char name[]="save.txt";
input.open(name, ios::in|ios:
ut|ios::noreplace);
if (input.fail())
{
input.open(name, ios::in|ios:
ut);
if (input.fail())
cout<<"this shows up at runtime";
}
else
{
cout<<"Enter Player 1 name: ";
cin>>players[1];
cout<<"Enter Player 2 name: ";
cin>>players[2];
input<<players[1]<<endl<<players[2];
}
input>>players[1]>>players[2];
cout<<players[1]<<' '<<players[2]<<endl;
system("pause"
;
}
and i was wondering if anyone could help me out. the file doesn't open if it was created, so when i try to load to the 'players' variables, nothing happens and the default values remain. ps, players is declared as:
char players[3][20]={"","Player 1","Player 2"};
void loadstats()
{
fstream input;
char name[]="save.txt";
input.open(name, ios::in|ios:
if (input.fail())
{
input.open(name, ios::in|ios:
if (input.fail())
cout<<"this shows up at runtime";
}
else
{
cout<<"Enter Player 1 name: ";
cin>>players[1];
cout<<"Enter Player 2 name: ";
cin>>players[2];
input<<players[1]<<endl<<players[2];
}
input>>players[1]>>players[2];
cout<<players[1]<<' '<<players[2]<<endl;
system("pause"
}
and i was wondering if anyone could help me out. the file doesn't open if it was created, so when i try to load to the 'players' variables, nothing happens and the default values remain. ps, players is declared as:
char players[3][20]={"","Player 1","Player 2"};