a simple question about files
I am learning files in c++.
I wrote this program .
Code:
#include <fstream.h>
#include <iostream.h>
struct st{
char name[21];
int age;}test;
int main(){
int i;
ofstream fp("myfile.txt");
if(!fp){
cout << "error";
return 0;}
for(i=0;i<3;++i){
cin>>test.name;
cin>>test.age;
if(test.age>30)
fp.write((char*)&test,sizeof(struct st));}
fp.close();
return (0);}
my problem is when I check the file (myfile) after running this program there is no age in it .
for example if I enter 40 the program get it as aski code and write '(' instead of 40 in the file .
what can I do?
my another question is : if I have c++ compiler in "c:\bin" is it possible to make the file in another place for exampl in D drive ?
tnx