Need help getting data from my database
Hey all I was working on my first database project and I came across a problem when I wanted to get information from it here is the code
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;
void create();
void search();
void showall();
string fname;
string lname;
int idnumber;
int main(){
cout << "Database" << endl;
cout << "1.Create a new data" << endl;
cout << "2.Search for a data" << endl;
cout << "3.Show all of the data" << endl;
cout << "4.Exit" << endl;
int choose;
cin >> choose;
switch(choose){
case 1:
create();
case 2:
search();
case 3:
showall();
case 4:
break;
}
return 0;
}
void create(){
system("cls");
ofstream myfile("Data.txt", ios::app);
string fname;
string lname;
int idnumber;
cout << "Enter your first name:";
cin >> fname;
cout << "Enter your last name:";
cin >> lname;
cout << "Enter the id number:";
cin >> idnumber;
myfile << fname << " " << lname << " " << idnumber << endl;
myfile.close();
}
void search(){
ifstream myfile("Data.txt");
string fname;
string lname;
int idnumber;
int id;
cout << "Enter the three digit Id: " << endl;
cin >> id;
while (fname >> lname >> idnumber){
if(id == idnumber){
system("cls");
cout << "Member found" << endl;
cout << "Name" << " " << "Last name" << endl;
cout << "----------------------------" << endl;
cout << fname << " " << lname << endl;
}
if(!(id == idnumber){
system("cls");
cout << "No member found" << endl;
}
}
void showall(){
}
|
The error code is to long to fit in here
Bump.
Still have the problem
Bump.?
Line 60:
1 2
|
//while ( fname >> lname >> idnumber ){
while ( myfile >> fname >> lname >> idnumber ){
|
Line 70:
1 2
|
//if ( !( id == idnumber ){
if ( id != idnumber ){
|
Before
void showall(){
, add a closing brace to terminate the earlier function.
Topic archived. No new replies allowed.