From d1616c8106caf1d6509ce3119e6a7c3f99fcf175 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 17 Oct 2020 19:30:29 +0300 Subject: echo: read if stdin if no args --- test/echo.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/echo.cpp b/test/echo.cpp index 8f01953..7354e7e 100644 --- a/test/echo.cpp +++ b/test/echo.cpp @@ -11,12 +11,25 @@ // clang-format on #include +#include int wmain(int argc, wchar_t* argv[]) { + _setmode(_fileno(stdin), _O_U16TEXT); _setmode(_fileno(stdout), _O_U16TEXT); + _setmode(_fileno(stderr), _O_U16TEXT); - for (int i = 1; i < argc; ++i) { - std::wcout << argv[i] << L'\n'; + --argc; + ++argv; + + if (argc > 0) { + for (int i = 0; i < argc; ++i) { + std::wcout << argv[i] << L'\n'; + } + } else { + std::wstring line; + while (std::getline(std::wcin, line)) { + std::wcout << line << L'\n'; + } } return 0; } -- cgit v1.2.3