C++ 파일 읽기/쓰기(C++ File Read/Write Example)
C++ 파일 읽기/쓰기 Hello World 입니다. :3
#include <fstream> #include <iostream> using namespace std; int main() { string filePath = "test.txt"; // write File ofstream writeFile(filePath.data()); if( writeFile.is_open() ){ writeFile << "Hello World!\n"; writeFile << "This is C++ File Contents.\n"; writeFile.close(); } // read File ifstream openFile(filePath.data()); if( openFile.is_open() ){ string line; while(getline(openFile, line)){ cout << line << endl; } openFile.close(); } return 0; }
Hello World! This is C++ File Contents.