E D R , A S I H C RSS

구조체 파일 입출력

~cpp
#include <iostream>
using namespace std;

struct Person{
	char name[10];
	int age;
	char phone[20];
};

int main()
{
	Person p;
	cout << "Input name : " ;
	cin >> p.name;
	cout << endl << "Input age : ";
	cin >> p.age;
	cout << endl << "Input phone number : " ;
	cin >> p.phone;

	cout << p.name << p.age << p.phone ;

	system("pause");
	

	FILE *fpt;
	fpt = fopen("struct.txt" , "wb");
	//fread(&p, sizeof(Person), 1 , fpt); // (주소, 구조체 크기, 구조체 개수, 파일 )
	fwrite(&p, sizeof(Person), 1, fpt);
	fclose(fpt);

	FILE *fp;
	fp = fopen("struct.txt", "rb");
	fread(&p, sizeof(Person), 1, fp);
	fclose(fp);
	return 0;


}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:45
Processing time 0.0090 sec