1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
 
int main()
{
    string str = "파일에씁시다.";
    ofstream ofs("file.txt");   //file.txt 파일을 연다.
    ofs << str;   //file.txt 파일에 str 문자열을 쓴다.
    ofs.close();    //파일을 닫는다.
    ifstream ifs("file.txt");   //file.txt 파일을 다시 열고
    ifs >> str;   //파일의 내용을 str에 저장한다.
    cout << str << endl;    //파일로부터 읽은 내용을 모니터 화면에 출력한다.
    ifs.close();    //파일을 닫는다.
    return 0;
}
Posted by 빵원군
,