Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- /*
- * ifstream
- * ofstream
- * fstream
- */
- int main()
- {
- std::ofstream outf;
- outf.open("file.txt");
- if (!outf) { std::cout << "IO ERROR!\n"; return 1; }
- //outf << "Hello, from C++ file io programm!\n";
- //outf << "Second string" << '\n';
- //outf << "Some numbers " << 123 << '\n';
- for (int i{ 100000 }; i < 100005; ++i)
- {
- //outf << "Line # " << i << '\n';
- outf << i << '\n';
- }
- //outf << "Some bool value " << (true ? "true" : "false") << '\n';
- //outf << "Some double literal " << 36.6 << '\n';
- outf.close();
- char str[200];
- int readVal{};
- std::ifstream inf;
- inf.open("file.txt");
- if (!inf) { std::cout << "IO ERROR!\n"; return 1; }
- //while (!inf.eof())
- //{
- // inf.getline(str, 200);
- // std::cout << str << '\n';
- //}
- while (!inf.eof())
- {
- inf >> readVal;
- if (inf.fail()) { break; }
- std::cout << "Read from file: " << readVal << '\n';
- //inf.ignore(100, '\n');
- }
- inf.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement