Okay so Im trying to learn how to write to a txt file and read it. I am still new to programming so I am a big noob :) However, I have come across a problem with my set out. Is there any other errors aswell?
// Cash Register.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include "Cash Register.h"
usingnamespace std;
int main()
{
cin >> Balance;
EndBalance();
return 0;
}
// Open Balance function
void StartBalance()
{
// Aint done this yet
}
// Save Balance function
void EndBalance()
{
EndBalance.open ("EndBalance.txt"); // EndBalance is not recognized either
EndBalance << Balance; // balance is not recognized
EndBalance.close();
};
Cash Register.h
1 2 3 4 5 6 7
#pragma once
class CashRegister
{
ofstream EndBalance;
int Balance;
}
I really think you should learn to use functions before you try to learn how to use a class. You have never declared a variable named Balance, in either main() or EndBalance(). If you're intending to use your class you've never declared an instance of that class either.
The two member variables of your class (EndBalance and Balance) only exist when there is a CashRegister instance (object) to go along with them. I would suggest reading the site's tutorial, where it makes an instance of a Rectangle class, with a length and width property.
I would also not name a function that same as a potential variable.