Data won't flush into ofstream

I wrote this program to count the number of days I've been bored since today
The program works by loading the number of days from a file named bored, and then adding 1 to this number. The updated number of days bored is SUPPOSED to be saved back in the file - but this does not happen and I don't understand why. I've "bolded" the relevant part of the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>
using namespace std;

int getDaysBored();
bool areYouBored();
void updateDaysBored(int);
int string2int(string);

int main()
{
	int days = getDaysBored();
	if(areYouBored())
	{
		days++;
		cout<<"You've been bored for "<<days<<" days since 9/11/2010."<<endl;
	}
	updateDaysBored(days);
	return 0;	
}

int getDaysBored()
{	
	string days_bored;
	ifstream iFile;
	iFile.open("~/Desktop/C++/Bored/bored.txt");
	getline(iFile,days_bored);
	int days = string2int(days_bored);
	return days;
}

bool areYouBored()
{
	char response;
	cout<<"Are you Bored today (Y/N)?"<<endl;
	cin>>response;
	if(response == 'Y' || response == 'y'){return true;}
	else return false;	
}

void updateDaysBored(int days_bored)
{
	ofstream oFile;
	oFile.open("~/Desktop/C++/bored/bored.txt");
	oFile<<days_bored<<endl;
	oFile.flush();
}

int string2int(string days_bored)
{
	int days = atoi(days_bored.c_str());
	return days;
	
}
Are you in a case sensitive environment?
Because you have iFile.open("~/Desktop/C++/Bored/bored.txt"); and oFile.open("~/Desktop/C++/bored/bored.txt");

I hadn't noticed that, but even after fixing it - the problem remains.
Last edited on
Topic archived. No new replies allowed.