Well Guys! I was learning how to read and write class objects from & to file respectivily. And here is a small code that i made......
As far as the code goes its all well.... And i am getting what i want....
But what i want to know is, where is the file that i am using saved?? Here the file is BLAHBLAH.dat. I cannot find it in any of the folders in the solution folder. And even a system full search didn't help. So where is it saved.....
I use Microsoft Visual C++ 2010 Express Edition.
Here is the code:
#include<iostream>
#include<fstream>
using namespace std;
class test
{
char name[10];
int grade;
int mark;
public:
void getinfo();
void showinfo();
};
void test::getinfo()
{
cout<<"Enter the Name"<<endl;
cin>>name;
cout<<"Grade??"<<endl;
cin>>grade;
cout<<"Mark?"<<endl;
cin>>mark;
}
void test::showinfo()
{
cout<<"Name: "<<name<<endl;
cout<<"Grade: "<<grade<<endl;
cout<<"Mark: "<<mark<<endl;
}
int main()
{
char opt;
int i;
fstream blah;
blah.open("BLAHBLAH.dat",ios::in|ios::out);
test a[5];
for(i=1;i<=2;i++)
{
cout<<"Enter the Record "<<i+1<<endl;
a[i].getinfo();
cout<<endl<<endl;
a[i].showinfo();
cout<<endl;
blah.write((char *)& a[i],sizeof(a[i]));
}
blah.seekg(0);
do
{
cout<<"Which record would you like to print?"<<endl;
cin>>i;
blah.read((char *)& a[i], sizeof (a[i]));
a[i].showinfo();
cout<<endl;
cout<<"Would you like to continue???"<<endl;
cin>>opt;
}while(opt=='y'||opt=='Y');
blah.close();
system("PAUSE");
return 0;
}
I know, in this code, i just use the file for the runtime and not for multiple executions.
Usually at school, where we use turbo c++ (Horrible) the file could be seen in the folder where the cpp file is saved......
Thanks in advance guys........