Created
April 24, 2024 04:09
-
-
Save JiaChangGit/8f5d7f40578fbb2530e6fa110352e557 to your computer and use it in GitHub Desktop.
111-cpp_io-ifstreamTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <iostream> | |
using namespace std; | |
int main() { | |
ifstream in1; | |
in1.open("ifstreamTest1.txt"); | |
if (in1.fail()) { | |
cout << "file opening is failed...\n"; | |
exit(1); | |
} | |
while (!in1.eof()) { | |
int value = 0; | |
in1 >> value; | |
cout << value << "\n"; | |
cout << "good()=" << in1.good() << ","; | |
cout << "fail()=" << in1.fail() << ","; | |
cout << "bad()=" << in1.bad() << ","; | |
cout << "eof()=" << in1.eof() << "\n"; | |
if (in1.good() == false) { | |
break; | |
} | |
} | |
in1.close(); | |
in1.open("ifstreamTest2.txt"); | |
if (in1.fail()) { | |
cout << "file opening is failed...\n"; | |
exit(1); | |
} | |
while (!in1.eof()) { | |
int value = 0; | |
in1 >> value; | |
cout << value << "\n"; | |
cout << "good()=" << in1.good() << ","; | |
cout << "fail()=" << in1.fail() << ","; | |
cout << "bad()=" << in1.bad() << ","; | |
cout << "eof()=" << in1.eof() << "\n"; | |
if (in1.good() == false) { | |
break; | |
} | |
} | |
in1.close(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment