// Filesave.cpp
#include <iostream>
#include <fstream>
using namespace std;    // cin, cout을 사용하기 위한 namespace 선언

int main(int argc, char**argv)
{
  int No;
  char name[20];
  char flag;
 
  ofstream fout;
  fout.open("aaa.dat");
  //fout.open("aaa.dat", ios::app); 파일 추가일 경우
 
  if( fout == NULL )
  {
    cout << "파일을 열 수 없습니다." << endl;
  }
  else
  {
    do {
      cout << "번호 : "; cin >> No; fout << No << endl;
      cout << "이름 : "; cin >> name; fout << name << endl;
      cout << "계속 진행?(Y / N)"; cin >> flag;
    } while( (flag == 'Y') (flag == 'y') );
  }
 
  fout.close();
 
  // 파일 내용 출력 부분
  ifstream fin;
  fin.open( "aaa.dat" );
 
  int number;
  char names[20];
 
  if( fin == NULL )
  {
    cout << "파일을 열 수 없습니다." << endl;
  }
  else
  {
    while( fin.eof() == false )
    {
      fin >> number;
      fin >> names;
     
      if(fin.eof() == true) break;
      cout << "번호 : " << number << endl;
      cout << "이름 : " << names << endl;
    };
  }
 
  fin.close();
 
  return 0;
}
 
2006/05/13 23:36 2006/05/13 23:36

글 걸기 주소 : 이 글에는 트랙백을 보낼 수 없습니다

덧글을 달아 주세요