void writingTransactionToFile(string transaction)
{
string temp;
int test;
ifstream myfile("transactionlog.txt");
ofstream tempfile ("tempfile.txt", ios::app);
if (tempfile.is_open())
{
tempfile << transaction;
if(myfile.is_open())
{
while(!myfile.eof())
{
getline(myfile,temp);
cout << temp;
tempfile << temp << endl;
}
} else {
cout << "Unable to open file.";
}
tempfile.close();
myfile.close();
} else
cout << "Unable to open file";
test = rename("tempfile.txt", "transactionlog.txt");
if(test != 0)
perror("Error: ");
cout << test;
}
Ok so its mainly the rename function that doesn't work. It just returns the value -1. perror doesn't return any error.
Not sure why it doesn't like it?