fstream
헤더는 c++에서의 파일 입출력 헤더이다.std::cout
, std::cin
과 유사하게 시프트 연산을 통해 사용할 수 있다.
fstream
헤더에는 총 세 가지 클래스가 존재한다.
ifstream
ofstream
fstream
std::ifstream fin(filename);
//파일 연결
if (fin.fail())
{
std::cerr << "Error: No '" << filename << "' found" << std::endl;
return (1);
}
char out;
while (fin.get(out))
std::cout << out;
while (buf.find(s1) != std::string::npos)
{
index = buf.find(s1);
buf.erase(index, s1.length());
//s1지우고
buf.insert(index, s2);
//s2넣기
}
std::ofstream fout(filename + ".replace");
fout << buf;