1) The whole program is very large so I just gave the function.
2) Not sure, but why should it close? Is it the WriteFileScore.close() function?
3) The block of code I posted in my first post just closed without making the file (in case you were wondering). Code block A. works fine as its own program, but it wont work with the big program I am doing. Code block B. is the complete function that I tried to use in my program. Block B. is just code block A., but instead of using the int "score", it uses "player.score". Code block B. gives the same problem as the first block of code i posted.
Thanks
A
Code:
#include <iostream>
#include <fstream>
#include <conio2.h>
using namespace std;
int main()
{
char name[50];
char exit;
int score = 10;
cout << "Please enter you name for the High Scores list : ";
cin.getline(name, 50);
ofstream WriteFileScore("HiScores.txt");
if(!WriteFileScore.is_open())
{ //The file did not open
cout << "Error Opening HiScores.txt.";
exit = getch();
system("Pause");
}
else
{
WriteFileScore << score;
WriteFileScore.close();
}
ofstream WriteFileName("HiScoreNames.txt");
if(!WriteFileName.is_open())
{ //The file did not open
cout << "Error Opening HiScoreNames.txt.";
exit = getch();
system("Pause");
}
else
{
WriteFileName << name;
WriteFileName.close();
}
}
B.
Code:
void HiScores()
{
char name[50];
char exit;
cout << "Please enter you name for the High Scores list : ";
cin.getline(name, 50);
ofstream WriteFileScore("HiScores.txt");
if(!WriteFileScore.is_open())
{ //The file did not open
cout << "Error Opening HiScores.txt.";
exit = getch();
system("Pause");
}
else
{
WriteFileScore << player.score;
WriteFileScore.close();
}
ofstream WriteFileName("HiScoreNames.txt");
if(!WriteFileName.is_open())
{ //The file did not open
cout << "Error Opening HiScoreNames.txt.";
exit = getch();
system("Pause");
}
else
{
WriteFileName << name;
WriteFileName.close();
}
}