diff options
Added solutions from oop seminar 2
1 files changed, 22 insertions, 0 deletions
| -rw-r--r-- | Year 1/Object-oriented Programming/Solutions Sem. 02/exercise01.cpp | 22 |
diff --git a/Year 1/Object-oriented Programming/Solutions Sem. 02/exercise01.cpp b/Year 1/Object-oriented Programming/Solutions Sem. 02/exercise01.cpp new file mode 100644 index 0000000..a9517ca --- /dev/null +++ b/Year 1/Object-oriented Programming/Solutions Sem. 02/exercise01.cpp @@ -0,0 +1,22 @@ +#include <iostream> // cin, cout +#include <fstream> // ifstream + +const int LINE_BUFFER_SIZE = 1024; + +int main() { + std::ifstream sourceFile("exercise01.cpp"); + + if (!sourceFile.is_open()) { + std::cout << "Error: Couldn't open file!" << std::endl; + return -1; + } + + char buffer[LINE_BUFFER_SIZE]; + while (!sourceFile.eof()) { + sourceFile.getline(buffer, LINE_BUFFER_SIZE); + std::cout << buffer; + if (!sourceFile.eof()) std::cout << std::endl; + } + + sourceFile.close(); +} |
