Error compiling a program

Hi, I'm trying to write a program to keep track of money, using the read/write function. I've tried fixing it, but this is the latest error I got in the compiler: financetrack.cpp: In function ‘int main()’:
financetrack.cpp:31: error: no match for call to ‘(std::string) (const char [16])’
financetrack.cpp:49: error: no match for call to ‘(std::string) (const char [11])’


I'm using linux, but here's the code. I've included comments. This is the code that produced the error above. I'm not sure what the problem is, or how to fix it. By the way, I apologize if it's a little long for the forum.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{

int choice; //option to choose
int checkin; //amount recieved
int spent; //amount spent
int bills; //total amount for bills
int remain; //total money remaining after spendings and bills
remain = checkin - bills - spent; //function for getting remain value
string date; //date the money was spent
string subject; //purchases made (items)
string month; //month the check was recieved


cout <<" Finance Tracker v1.0 \n\n"; //name of program
cout <<" What would you like to do?\n\n";
cout <<" 1 Monthly Check Log\n"; // Check logger and remaining amount logger
cout <<" 2 Spendings Logger\n"; // log amount spent and remaining money
cin >> choice;
if (choice == 1)
{
cout <<"Monthly Check Log\n\n"; //log the amount for check
cout <<"Month: ";
getline(cin,month);
cout <<"Check Total: ";
cin >> checkin;
cout <<"Bills: ";
cin >> bills;
cout <<"Cash Remaining: "<<remain<<"\n\n";
ofstream myfile; //writing function to log all the input
myfile.open("Finance.txt"); //file to write to
myfile << (month)(" Check Amount: ")(checkin)(" Bills: ")(bills)(" Total Remaining: ")(remain); //values to write
myfile.close();
return 0;

}

else if (choice == 2)
{
cout <<"Spendings Logger \n\n";
cout <<"Date: ";
getline(cin,date);
cout <<"Subject: ";
getline(cin,subject);
cout <<"Spent: ";
cin >> spent;
cout <<remain;
ofstream myfile;
myfile.open("Finance.txt");
myfile << (date)(" Subject: ")(subject)(" Remaining: $")(remain)("\n\n");
myfile.close();
}
else
{
cout <<"Incorrect Choice\n"; // close program if the input for choice does not match the optional choices
return 0;
}
}
myfile << (month)(" Check Amount: ")(checkin)(" Bills: ")(bills)(" Total Remaining: ")(remain); //values to write

Why do you think that line of code makes sense? You seem to have a general idea of how streams work but that line is incomprehensible.
I haven't programmed in C++ in quite a while. At least a year and a half, and the last time I used a write function, it was for something really simple, but I don't remember how to use it, and I'm not sure how that line should be written in order to work. The syntax is the problem I'm having.
I'ts difficult to say what you are actually intending to do but perhaps you should replace that little line with this:
myfile << month << " Check Amount: " << checkin << " Bills: " << bills << " Total Remaining: " << remain; //values to write
Same way as you would do it with cout or cin.
[laughing at myself] I see it now. But I still can't find a way to keep the entries in the file. Is there a way to get around the file being erased and rewritten with each new entry?
When opening the file, open it in append mode (ios::app I think). It is opened in truncate mode by default, which is why it is erased.
Worked like a charm, thank you all so much for your help. I got it up and running and am currently working on expanding the program, improving the bugs, and making it into a stable program to use every day. : )
Topic archived. No new replies allowed.