file problem

hey guys
i have a little problem with files in read (line 29)

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
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;

struct student{
	
	int code;
	string name;
};

fstream p;

int main(){
	
	student data;
	
	cout<<"enter code: ";
	cin>>data.code;
	
	cout<<"enter name: ";
	cin>>data.name;
	
	p.open("A:\\heaven.dat",ios::in|ios::out|ios::binary);
	p.write(data.name.c_str(),sizeof(char)*data.name.size());
	p.close();
	
	p.open("A:\\heaven.dat",ios::in|ios::out|ios::binary);
	p.read(data.name.c_str(),sizeof(char)*data.name.size());
	p.close();
	
	return 0;
}
Last edited on

#include <string.h>
What's this C header doing here?

Line 29 data.name.c_str()
This returns a const char*, but the function wants a char*. Wrong type.
Last edited on
got it
thank you
Topic archived. No new replies allowed.