Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <iostream>
- #include <fstream>
- #include <stdexcept>
- #include <string>
- using namespace std;
- void readFromFile(const string& filepath) {
- ifstream file(filepath);
- if (!file.is_open()) {
- throw runtime_error("Не вдалося відкрити файл: " + filepath);
- }
- cout << "Вміст файлу \"" << filepath << "\":" << endl;
- string line;
- while (getline(file, line)) {
- cout << line << endl;
- }
- file.close();
- }
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- string path;
- cout << "Введіть повний шлях до файлу: ";
- getline(cin, path);
- try {
- readFromFile(path);
- }
- catch (const runtime_error& e) {
- cout << "Помилка: " << e.what() << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement