ofstream error

how can i correct his erroer


#include <iostream>
#include <iomanip>
#include <time.h>
#include <windows.h>
#include <vector>
#include <fstream>
#include <string>
#include <fstream>

using namespace std;


int getMonth(int month);
int getYear(int year);
int computeOffset(int year, int month);
int numDaysYear(int year);
int numDaysMonth(int year, int month);
bool isLeapYear(int year);
void display(int year, int month, int offset);
int getDay(int year, int month);

// one event information
class Event
{
public:
Event();
Event(int id, int year, int month, int day, string description);
int getID();
int getYear();
int getMonth();
int getDay();
string getDescription();
private:
int _id;
int _year;//date
int _month;
int _day;
string _description;
};

Event::Event(){
_id = 0;
_year = 2014;
_month = 6;
_day = 27;
_description = "test";
}

Event::Event(int id, int year, int month, int day, string description){
_id = id;
_year = year;
_month = month;
_day = day;
_description = description;
}

int Event::getID(){
return _id;
}

int Event::getYear(){
return _year;
}

int Event::getMonth(){
return _month;
}

int Event::getDay(){
return _id;
}

string Event::getDescription(){
return _description;
}

// all events
class Events
{
public:
Events();
void addEvent(int year, int month, int day, string description);
void deleteEvent(int id);
void saveEvents(string filename);
void loadEvents(string filename);
void displayAllEvents();
private:
vector<Event> events;// use STL container vector to contain all events
int ID;
};

Events::Events(){
ID=0;
}

void Events::addEvent(int year, int month, int day, string description){
ID++;
Event eventTemp(ID, year, month, day, description);
events.push_back(eventTemp);
}

void Events::deleteEvent(int id){
vector<Event>::iterator it = events.begin();
while (it != events.end())
{
if ((*it).getID()== id)
{
events.erase(it++);
}
else
{
it++;
}
}
}

void Events::saveEvents(string filename){
ofstream saveFile(filename, ios_base::out);
vector<Event>::iterator it = events.begin();
while (it != events.end())
{
saveFile<<(*it).getID()<<" "<<(*it).getYear()<<"/"<<(*it).getMonth()
<<"/"<<(*it).getDay()<<" "<<(*it).getDescription()<<endl;
it++;
}

saveFile.close();
}

void Events::loadEvents(string filename){

}

void Events::displayAllEvents(){
vector<Event>::iterator it = events.begin();
while (it != events.end())
{
cout<<(*it).getID()<<" "<<(*it).getYear()<<" "<<(*it).getMonth()
<<" "<<(*it).getDay()<<" "<<(*it).getDescription()<<endl;
it++;
}

}

tm* getSystemTime()
{
time_t timer;
time(&timer);
tm* t_tm = localtime(&timer);

cout<<"today is "<<t_tm->tm_year+1900<<" "<<t_tm->tm_mon+1<<" "<<t_tm->tm_mday<<endl;
return t_tm;
}


int main()
{
int numDays;
int offset;
int month;
int year;
int day;
tm* currentYearAndMonth = getSystemTime() ;

string filename = "events.txt";

Events events;

month = currentYearAndMonth->tm_mon+1;

year = currentYearAndMonth->tm_year+1900;

offset = computeOffset(year, month);

display(year, month, offset);

char m;
int temp;
string description="";
//string filename;
while(1){

cout<<"please select the operation: "<<endl;

cin>>m;

switch(m){
case 'N' :
if(month == 12) {
year++;
month = 1;
}else{
month++;
}
break;
case 'P' :
if(month == 1) {
year--;
month = 12;
}else{
month--;
}
break;
case 'C' :
month = getMonth(month);
year = getYear(year);
break;
case 'A' :
// To do ...
month = getMonth(month);
year = getYear(year);
day = getDay(year, month);

cout<<"please input the event description: ";
cin>>description;
events.addEvent(year, month, day, description);
break;
case 'L' :
// To do ...
events.displayAllEvents();
break;
case 'D' :
// To do ...
cout<<"please input the event id which you want cancel: ";
cin>>temp;
events.deleteEvent(temp);
break;
case 'S' :
// To do ...
filename = "events.txt";
events.saveEvents(filename);
break;
case 'R' :
// To do ...

break;
case 'Q' :
// To do ...
cout<<"ByeBye~~"<<endl;
return 0;
break;
default:
cout<<"error operation ! !"<<endl;
}
offset = computeOffset(year, month);
cout<<offset<<endl;
display(year, month, offset);


}


return 0;
}

int getMonth(int month)
{
cout << "Enter a month number: ";
cin >> month;

while ( month < 1 || month > 12)
{
cout << "Month must be between 1 and 12.\n"
<< "Enter a month number: ";
cin >> month;
}

return month;
}


int getYear(int year)
{
cout << "Enter year: ";
cin >> year;

while ( year < 1753)
{
cout << "Year must be 1753 or later.\n"
<< "Enter year: ";
cin >> year;
}
return year;
}



int getDay(int year, int month)
{
int day;
cout << "Enter day: ";
cin >> day;
int _numDaysMonth = numDaysMonth(year, month);

while ( day < 1 || month > _numDaysMonth)
{
cout << "day number is invalid.\n"
<< "Enter valid day number: ";
cin >> year;
}
return day;
}


int computeOffset(int year, int month)
{
int offset = 0;
int daysNumToNow = 0;
//int count = year - 1753;
int i;

for( i = 1753 ; i < year ; i++)
if( isLeapYear( i ) )
daysNumToNow += 366 ;
else
daysNumToNow += 365 ;
for( i = 1 ; i < month ; i++ )
daysNumToNow += numDaysMonth( year , i );

int firstDayOfTheMonth = 1;
//now, daysNumToNow is the number of days from 1800 to the year you insert (not including the days of the year)
daysNumToNow += firstDayOfTheMonth - 1 ;



offset = ( daysNumToNow + 50 ) % 7 ;
return offset;
}





int numDaysYear(int year)
{
int daysYear = 365 + isLeapYear(year);
return daysYear;
}

int numDaysMonth(int year, int month)
{
int daysMonth;

if ( month == 1)
daysMonth = 31;
else if ( month == 2)
{
if (isLeapYear(year) == true)
daysMonth = 29;
else
daysMonth = 28;
}
else if ( month == 3)
daysMonth = 31;
else if ( month == 4)
daysMonth = 30;
else if ( month == 5)
daysMonth = 31;
else if ( month == 6)
daysMonth = 30;
else if ( month == 7)
daysMonth = 31;
else if ( month == 8)
daysMonth = 31;
else if ( month == 9)
daysMonth = 30;
else if ( month == 10)
daysMonth = 31;
else if ( month == 11)
daysMonth = 30;
else if ( month == 12)
daysMonth = 31;

return daysMonth;
}


bool isLeapYear(int year)
{
//if ( year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
if ( (year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return true;
else
return false;
}

void display(int year, int month, int offset)
{
int dayOfWeek;
int day;

cout << endl;
if ( month == 1)
cout << "January";
else if ( month == 2)
cout << "February";
else if ( month == 3)
cout << "March";
else if ( month == 4)
cout << "April";
else if ( month == 5)
cout << "May";
else if ( month == 6)
cout << "June";
else if ( month == 7)
cout << "July";
else if ( month == 8)
cout << "August";
else if ( month == 9)
cout << "September";
else if ( month == 10)
cout << "October";
else if ( month == 11)
cout << "November";
else if ( month == 12)
cout << "December";


cout << ", " << year << "\n";
// Display month header
cout << " Su Mo Tu We Th Fr Sa\n";


for(int i = 1 ; i <= offset ; i++)
cout<< setw( 4 ) << " " ; //space


// The loop for displaying the days and ending the line in the right place
for ( dayOfWeek = 1; dayOfWeek <= numDaysMonth(year, month); dayOfWeek++ )
{
cout << " " << setw(2) << dayOfWeek;

if( 0 == ( dayOfWeek + offset ) % 7 )
cout<< endl;
}
cout<< endl;

return;
}





[/code]
Code is corect and should compile. There is no syntax errors. What exactly your promlem is?
am using code blocks..what compiler dd u use
126 error: no match function for call to 'std::basic_ofstream<char>::basic_ofstream(std::string, cont openmode&)'
Settings → Compiler → check have g++ follow C++11 ISO C++ language standard
thanx man
Hello!
If your problem is solved, it is very helpful to other users if you mark it as solved using the button at the top of the post.

Thanks!
Topic archived. No new replies allowed.