#include <fstream.h>
class Person
{
char emp_name[40];
int Tel;
public:
void ShowData()
{cout<<"Name: "<<emp_name<<endl<<"tel: "<<Tel;}
};

void main()
{
Person s1;
ifstream file("c:\\mydocuments\\db_add_tel.mdb");
file.read((char*)&s1,sizeof(s1));
s1.ShowData();

}


can anyone telme whats really happening aftet opening the add_tel file.
actually i don't know how to makethe screen stay because when i run the program(any)it just runs and exits without showin' whatse ever results.in this forum it was suggested sometime back to use system pause statement even that didn't worked so plz do reply..
secondally when i have to enter anything(string)i have to click at that pt(cursur) and then it takes input and that too only characters(no numbers).where's the problem???
am using borland 5.02

JUST add this line before return 0;
cin.get();
and see let me know if your problem is solved
Nabeel

#include <fstream.h>
class Person
{
char emp_name[40];
int Tel;
public:
void ShowData()
{cout<<"Name: "<<emp_name<<endl<<"tel: "<<Tel;}
};

void main()
{
Person s1;
ifstream file("c:\\mydocuments\\db_add_tel.mdb");
file.read((char*)&s1,sizeof(s1));
s1.ShowData();

}


can anyone telme whats really happening aftet opening the add_tel file.
actually i don't know how to makethe screen stay because when i run the program(any)it just runs and exits without showin' whatse ever results.in this forum it was suggested sometime back to use system pause statement even that didn't worked so plz do reply..
secondally when i have to enter anything(string)i have to click at that pt(cursur) and then it takes input and that too only characters(no numbers).where's the problem???
am using borland 5.02

How about this....

#include <fstream>
#include <iostream>
#include <string>
using namespace std;

class Person
{
char emp_name[40];
string Tel;
public:
void ShowData()
{cout<<"Name: "<<emp_name<<endl<<"tel: "<<Tel;}
};

int main()
{
Person s1;
ifstream file("c:\\mydocuments\\db_add_tel.mdb");
file.read((char*)&s1,sizeof(s1));
s1.ShowData();
cin.get(); //another options system("pause");
return 0;
}

>How about this....
How about not? By "improving" the code, you've broken it. Before, the Person class was a POD type and thus could be legally treated as a sequence of bytes (as stream.read does). And while performing a binary read into a class or struct type is immensely stupid due to portability issues, it's still legal. By changing the Tel member to string, you've introduced a non-POD member to the class and thus changed it to a non-POD type. Now using stream.read with that type is undefined.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.