/****************************************************************************** * This program simply copies a file to the console line by line. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ #undef NDEBUG #include "Utils.hpp" #include #include #include #include #include std::locale utf8loc(std::locale(), new std::codecvt_utf8); using namespace Utils; using namespace std; void read_text_file(wstring filespec) { wifstream ifh(filesystem::path(filespec).c_str()); if (!ifh.good()) { throw ios_base::failure(Utils::wchar_to_UTF8(L"Problem opening input file!")); } ifh.imbue(utf8loc); wstring line; while (getline(ifh, line)) { wcout << line << endl; } ifh.close(); } int main(int argc, char **argv) { setlocale(LC_ALL, "en_US.UTF-8"); wcout.imbue(utf8loc); wcin.imbue(utf8loc); if (argc != 2) { wcout << L"Syntax: " << Utils::UTF8_to_wstring(argv[0]) << L" {filename}" << endl; exit(1); } wstring const FILESPEC = Utils::UTF8_to_wstring(argv[1]); try { read_text_file(FILESPEC); } catch (ios_base::failure ex) { wcout << L"Error: " << Utils::exceptionMessage(ex) << endl; } catch (...) { wcout << L"Unexpected File Read Error" << endl; } return 0; }