Database Management System

Hi!
I am trying to make a console (CUI) database application which can store all my user names,passwords or stuff like that using fstream. All was going fine but I noticed something that when I add a new record, it overwrites the older one.

Is it possible to stop that?
Thank You.
Help will be highly appreciated.
Can't say for sure without seeing any code, but you probably aren't opening the file in append mode.
What does append mode mean?
Here is the code.
It is very unorganized and long but it is here:-
I chose to make it highly protected so the password will be asked everytime before going back to the main menu.

//start of code
#include "stdafx.h"
#include<iostream>
#include<fstream>
#include<windows.h>
#include<string>
#include<conio.h>
int main(int argc, char* argv[])
{
int longcompchoose;
int fiveback;
int formatback;
int toback;
long double pass;
char datainput[1000000];
using namespace std;
cout<<"Enter password for identification";
cin>>pass;
if(pass!=9111995)
{
cout<<"The password given was incorrect. Please restart the database";
}
else if(pass=9111995)
{
system("cls");
cout<<"Identification completed"<<endl;
cout<<"Welcome!\nAshish Mehrotra";
logincomp:
cout<<"\n\nThe options available are given below:-\n\n";
cout<<"1.Make a new record"<<endl;
cout<<"2.See current records"<<endl;
cout<<"3.Format and Empty Database"<<endl;
//cout<<"3.Help"<<endl;
cout<<"4.About"<<endl;
cout<<"5.Exit"<<endl;
cin>>longcompchoose;
switch(longcompchoose)
{
case 5:
{
system("exit");
break;
}
case 4:
{
system("cls");
cout<<" Database Management System"<<endl;
cout<<"\n\nThe Database Management System requirements:-";
cout<<"Microsoft Windows \n or \n Microsoft DOS(MS-DOS)";
cout<<"\n\nType the password to go back to main menu";
cin>>fiveback;
if(fiveback!=9111995)
{
system("exit");
}
else if(fiveback=9111995)
{
system("cls");
goto logincomp;
}
break;
}
default:
{
system("exit");
}
case 3:
{
ofstream my;
my.open ("mydb.dll");
my << system("cls");
my.close();
cout<<"Format completed";
cout<<"Enter the password to go back to main menu";
cin>>formatback;
switch(formatback)
{
case 9111995 :

system("cls");
goto logincomp;
break;

default :

system("exit");
break;
}
}
case 2:
{
system("cls");
string line;
ifstream myfile ("mydb.dll");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
myfile.close();
cout<<"\n\nPlease enter password to go back to the main menu";
cin>>toback;
switch(toback)
{
case 9111995:
system("cls");
goto logincomp;
break;

default:
system("exit");
break;
}
}}
else cout<<"Unable to open file due to some problem";
}
case 1:
cout<<"Enter the records.\nNote:-Records should be less than 1000000 alphabets\n ";
cin>>datainput;
ofstream lmabcd;

lmabcd.open("mydb.dll");

lmabcd << datainput;
lmabcd.close();
break;
}
}

}//end of code

Last edited on
Jeez, does anybody indent their code any more?
Why should anyone bother doing that much. The compiler does not look how organized is the code.
ofstream my("mydb.dll", ios::app); opens in append mode, which as http://cplusplus.com/reference/iostream/fstream/fstream.html says "Set the stream's position indicator to the end of the stream before each output operation." meaning it'll put everything you output on the end.
Thanks. Could you help me with my other post. It is named 'A Key Chart'.
Sorry could not give url.
Last edited on
lol

Jeez, does anybody indent their code any more?



Why should anyone bother doing that much. The compiler does not look how organized is the code.


cuz on forms... we are not a compiler
cuz on forms... we are not a compiler


I think what CoDeReBel was trying to say is, people should post their codes using proper tags.

Why should anyone bother doing that much. The compiler does not look how organized is the code.


That's right, compiler does not care, but the people who are trying to help you with your code are not compilers. And it is way too hard to read the code without proper tags used.

So please from next time use the proper tags for posting the code.
Topic archived. No new replies allowed.