Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- void write() {
- ofstream ofs("data.txt"); // RAII 패턴을 적용하고 있어 리소스 해제가 스택을 통해 이루어짐
- ofs << 0.0 << ' ' << -0.4 << '\n';
- ofs << -0.5 << ' ' << 0.2 << '\n';
- ofs << 0.5 << ' ' << 0.8 << flush;
- }
- void read() {
- ifstream ifs2("data.txt");
- float val2;
- cout << boolalpha;
- while (ifs2 >> val2) {
- cout << val2 << endl;
- cout << ifs2.fail() << ' ' << ifs2.eof() << endl;
- }
- cout << ifs2.fail() << ' ' << ifs2.eof() << endl;
- }
- int main() {
- write();
- read();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement