파일입출력(fstream)

DONGJE LEE·2022년 5월 9일
0

C++

목록 보기
2/12
post-thumbnail

우선 fstream 헤더를 넣어준다.

#include <fstream>

파일을 열고 닫으려면,

file.open("파일 경로", 모드);
file.close();

연 파일은 반드시 닫아주는 과정이 있어야 한다.

위에서 모드라고 하였는데 아래정보를 사용하면 된다.

ios::in //read
ios::out //write

Ex)

#include <iostream>
#include <fstream>
using namespace std;

int main(){
  fstream file;
  file.open("text.txt", ios::out); //쓰기 모드
  file << 1234;
  file.close();
  return 0;
}
profile
LiDAR & SLAM & Robotics & Autonomous System

0개의 댓글