0

I have the following code in my console application

    std::cout << "\nEnter Id: ";
    std::cout.flush();
    std::wcin >> inId;

    std::cout << "\nEnter Secret: ";
    std::cout.flush();
    std::wcin >> inSecret;

If i read the input from console i am getting the correct input. But if i redirected the input from a text file them I am getting empty(EOF) value. For MBCS it is working as expected.I couldn't figure out what is happening there in UNICODE. Can anyone help me on this? thanks in advance

senthil
  • 21
  • 4
  • 1
    What is the contents of the file you redirect from? What is its encoding? – Some programmer dude Apr 21 '17 at 11:06
  • file has the following sam xys27hdeo87 Encoding was utf-8 – senthil Apr 21 '17 at 11:24
  • Maybe there's something here that gives you some ideas: [How can I cin and cout some unicode text?](http://stackoverflow.com/questions/3207704/how-can-i-cin-and-cout-some-unicode-text) – Phil Brubaker Apr 21 '17 at 15:55
  • "*Encoding was utf-8*" - `std::wcin` can't read input in UTF-8. Use `std::cin` instead, or a separate `std::istream` that is attached to your platform's console API in binary mode, and then read in and convert from UTF-8 to UTF-16/32 yourself as needed (depending on the size of wchar_t). Which means you will have to first detect if STDIN is redirected and then read from it accordingly. Doing redirection detection is platform-specific, though, there is nothing in standard C++ to help with that. – Remy Lebeau Apr 25 '17 at 17:32

0 Answers0