1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct Database
{
string phone;
string name;
string address;
string Email;
};
int main()
{
char ch;
ofstream Dbase;
Dbase.open("Dbase.txt");
Database PI;
do{
cout << "\n Please enter a name: ";
getline(cin, PI.name);
Dbase << PI.name;
cout << " \n Please enter a phone number: ";
getline(cin, PI.phone);
Dbase <<"\n"<< PI.phone;
cout << " \n Please enter an address: ";
getline(cin, PI.address);
Dbase <<"\n"<< PI.address;
cout << " \n Please enter an Email: ";
getline(cin, PI.Email);
Dbase <<"\n"<< PI.Email<<endl;
Dbase.close();
cout <<"would you like to review the information you just entered: y/n\n";
cin >> ch;
if(ch=='y'|ch=='Y')
{
goto Overhere;
}
cout <<"\nwould you like to create another entry: y/n\n";
cin>>ch;
}while(ch=='y' || ch=='Y');
do{
Overhere:
ifstream infile;
infile.open("Dbase.txt");
infile >> PI.name>> PI.address >> PI.Email >> PI.phone;
cout << PI.name <<"\n"<< PI.address <<"\n"<< PI.Email <<"\n"<< PI.phone;
cout << "\n\nShould the program exit? y/n\n";
cin >> ch;
} while(ch=='n'|ch=='N');
return 0;
}
|
As far as i can see I have 3 flaws i am asking for help with.
1) when the info is being read from files, and i try printing the strings stored in the variables i only get the first word from each string.
2) at the end of the first do while loop if the user decides to create another entry the program prints the line please enter a name, then immediately after in a new line with no space, the line please enter a phone number.
3) Finally every time a new entry is made it overwrites the previous one.
I would also like to know how to search for something in the file and all info relating to it, view the entire file, and delete the file.
Thanks for all the help in advance.
P.s. I'm using Dev C++ and running windows 7 ultimate, 32 bit.