/****************************************************************************** * This program simply writes characters from the alphabet to a file. * * 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 write_text_file(wstring filespec) { wofstream ofh(filesystem::path(filespec).c_str()); if (!ofh.good()) { throw ios_base::failure(Utils::wchar_to_UTF8(L"Problem opening output file!")); } ofh.imbue(utf8loc); // Latin alphabet for (int c = 0x41; c <= 0x5A; ++c) { ofh.put(c); } ofh.put(L'\n'); // Greek alphabet for (int c = 0x391; c <= 0x3A9; ++c) { ofh.put(c); } ofh.put(L'\n'); // Cyrillic alphabet for (int c = 0x410; c <= 0x42F; ++c) { ofh.put(c); } ofh.put(L'\n'); // Katakana alphabet for (int c = 0x30A0; c <= 0x30FF; ++c) { ofh.put(c); } ofh.put(L'\n'); ofh.flush(); ofh.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 { write_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; }