#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; }
'C++ > C++11 공부노트' 카테고리의 다른 글
auto형 변수(초기값필요), decltype형(초기값 불필요) (0) | 2016.06.27 |
---|---|
별칭선언(using) (0) | 2016.06.24 |
tellp()와 seekp() 함수를 사용한 파일 쓰기 (0) | 2016.06.23 |