Whats wrong with my file streaming[it compiles fine]
Code:
#include <iostream> // The basic C++ header file
#include <fstream> // The header file used to make output and input files
#include <conio.c>
#include <string> // for strings[group of words/text]
#include <windows.h> // For some basic window function obviously
#define done 0
typedef void function; // not necessary, just the way I program
typedef unsigned short int Zint; // Also not necessary, Zint stands for ZOO Integer
class database // Our first class
{
public:
function GetInfo();
function LoadInfo(ifstream &fin);
function DCS(string sz, Zint x, Zint y, WORD color); // DCS stands for Draw Color String
private:
char *name;
Zint *age;
string eater; // strange, I know
ofstream fout;
}obf;
function database::GetInfo()
{
name= new char[30];
age= new Zint[10];
cout << "Input your fullname: ";
cin.getline(name, 30, '\n');
cout << "\nInput your age: ";
cin >> age[0];
fout.open("info.txt");
fout << "Name: " << name;
fout << "\nAge: " << age[0];
fout.close();
delete [] name;
delete [] age;
}
function database::LoadInfo(ifstream &fin)
{
fin.open("info.txt");
if (fin.fail() ) {
cout << "\nSorry, unable to find \"info.txt\"....." << endl; }
while (fin >> eater ) {
if (!fin.eof() ) {
cout << eater;
fin.clear(); }
else {
fin.close(); }
}
fin.close();
}
function database::DCS(string sz, Zint x, Zint y, WORD color)
{
HANDLE output= GetStdHandle(STD_OUTPUT_HANDLE);
COORD cursor={x, y};
SetConsoleCursorPosition(output, cursor);
SetConsoleTextAttribute(output, color);
cout << sz;
}
int main(Zint argc, char *argv[])
{
ifstream some;
Zint *numbers; numbers=new Zint[10];
database *zoo;
zoo= new database;
zoo->DCS("********************************", 20, 5, FOREGROUND_RED | FOREGROUND_INTENSITY);
zoo->DCS("**** The Main Menu!! ****", 20, 6, FOREGROUND_RED | FOREGROUND_INTENSITY);
zoo->DCS("**** ****", 20, 7, FOREGROUND_RED | FOREGROUND_INTENSITY);
zoo->DCS("**** 1. Print Info ****", 20, 8, FOREGROUND_RED | FOREGROUND_INTENSITY);
zoo->DCS("**** 2. Load Info ****", 20, 9, FOREGROUND_RED | FOREGROUND_INTENSITY);
zoo->DCS("**** ****", 20, 10, FOREGROUND_RED | FOREGROUND_INTENSITY);
zoo->DCS("********************************", 20, 11, FOREGROUND_RED | FOREGROUND_INTENSITY);
zoo->DCS("What is Thy Desire? ", 24, 13, FOREGROUND_RED | FOREGROUND_INTENSITY);
cin >> numbers[0];
switch(numbers[0]) {
case 1: clrscr();
zoo->GetInfo();
break;
case 2: clrscr();
zoo->LoadInfo(some);
break;
default:
break;
}
delete zoo;
cin.get();
return done;
}