diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2020-10-17 19:30:29 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2020-10-17 19:30:29 +0300 |
commit | d1616c8106caf1d6509ce3119e6a7c3f99fcf175 (patch) | |
tree | ace3002962d8296b5f34fc5eec9c2bb0e31aef6d | |
parent | cmake: minor tweaks (diff) | |
download | winapi-common-d1616c8106caf1d6509ce3119e6a7c3f99fcf175.tar.gz winapi-common-d1616c8106caf1d6509ce3119e6a7c3f99fcf175.zip |
echo: read if stdin if no args
-rw-r--r-- | test/echo.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
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 <iostream> +#include <string> 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; } |