Database Revamped: 'Expected ';' before ')' token' error
Hi, some of you might remember me from a database project I was working on ages ago, or, you might not ;).
Anyways, I've recently picked up my C++ projects again, and set about redoing the code for the Database program.
All was going well until I got weird errors that I didn't seem to be able to solve, and I was hoping someone on this board could help me.
Alright, here's the code:
Code:
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <clrscr.h> // Yesyes, a custom header thingy, but no credit 2 me, it's taken from the faq.
using namespace std;
/*
30-12-05 20:38
Thanks people of the cboard forum!!!
Special thanks:
xhi
xhi
xhi
xhi
*Repeat above 200000 times*
Me
*/
struct Database {
int id;
string name;
int age;
};
int main() {
Database emp;
int choice;
string name = "database/Member";
string dat = ".dat";
string sid;
...
...
} //Bad code starts below I think
if (choice == 1){
int id = 0;
ifstream fin;
stringstream s;
fin.open("database/Member1.dat");
for(!fin.bad()) {
string filename = " ";
id = id + 1;
s << id;
s >> sid;
filename = name + sid + txt;
fin.open(filename.c_str(), ios::binary);
fin.read((char *)(&emp), sizeof(emp));
cout << "Id: " << emp.id << endl << "Name: " << emp.name << endl << "Age: " << emp.age << "\n\n";
cin.get();
fin.close();
ifstream fin;
}
}
}
And these are the errors I get:
- 67 C:\Documents and Settings\Tim\Mijn documenten\My C++\FinFoutDbase.cpp expected `;' before ')' token
- 80 C:\Documents and Settings\Tim\Mijn documenten\My C++\FinFoutDbase.cpp expected primary-expression before '}' token
- 80 C:\Documents and Settings\Tim\Mijn documenten\My C++\FinFoutDbase.cpp expected `;' before '}' token
- 80 C:\Documents and Settings\Tim\Mijn documenten\My C++\FinFoutDbase.cpp expected primary-expression before '}' token
I get more then those, but basically they are all the same.
The compiler/editor I use is:
Bloodshed Dev C++ version 4.9.9.2
I have absolutely no idea as to where these erorrs are coming from, or how to solve them. Any ideas are welcome.
Database Revamp: File reading bug.
[Edit]
Found the answer, modified code to reflect.
[/Edit]
Hello, I have another problem with my Database project, and I was wondering if someone could give me some pointers.
This is the code:
Code:
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <clrscr.h> // Yesyes, a custom header thingy, but no credit 2 me, it's taken from the faq.
using namespace std;
/*
30-12-05 20:38
Thanks people of the cboard forum!!!
Special thanks:
xhi
xhi
xhi
xhi
*Repeat above 200000 times*
Me
*/
struct Database {
int id;
char name[31];
int age;
};
int main() {
Database emp;
int choice;
string name = "database/Member";
string dat = ".dat";
string sid;
cout << "Read(1) or write(2)?";
cin >> choice;
cin.ignore();
...
...
if (choice == 1){
int id = 1;
int x = 0;
ifstream fin;
for(;;id++) {
stringstream s;
s << id;
s >> sid;
string filename = " ";
filename = name + sid + dat;
fin.open(filename.c_str(), ios::binary);
if (fin.fail()) {
break;
}
fin.read((char *)(&emp), sizeof(emp));
cout << "Id: " << emp.id << endl << "Name: " << emp.name << endl << "Age: " << emp.age << "\n\n";
cin.get();
fin.close();
ifstream fin;
}
}
}
The read function is supposed to read all the files in the dir, and then stop reading, but it doesn't. It reads all the files in the dir, but when it gets to the last file, it just shows it over and over again. Any ideas as to ho to solve this?
TIA