0

I'm new to developing apps on Windows 10 IoT, so I made little test application just to test how to read input from stdin on a console app on a Raspberry Pi 2 running Windows 10. Now I know that this is not the average use case, but my original app has the purpose to only serve as a demo.

My little code in C++ (for reasons I'm restricted to C++) so far is very simple:

#include "pch.h"

int main(int argc, char **argv) {
  char buffer[1024];

  std::cin.getline(buffer, 1024);
  printf("%s \n", buffer);
}

The problem I face is, that the line

std::cin.getline(buffer, 1024); 

seems to be omitted. All the program does is printing an empty line. So there isn't even time to type anything to stdin. Maybe it's worth mentioning that I'm testing this via a powershell remote session so maybe this has anything to do with it.

My questions are now:

  1. Is it even possible to read a line from stdin? (I guess so)
  2. Am I doing it wright? (Certainly not)
  3. What is the correct/clean way to do so? Where is my error?
Sebastian
  • 143
  • 9
  • IoT doesn't make any difference. Why are you using a char buffer instead of `std::string` though? That's C, not C++ code. Check this [getline](http://www.cplusplus.com/reference/string/string/getline/) example. It's enough to write :`std::string name;std::getline (std::cin,name);` – Panagiotis Kanavos Jan 27 '17 at 16:17
  • Possible duplicate of [How to read a complete line from the user using cin?](http://stackoverflow.com/questions/5455802/how-to-read-a-complete-line-from-the-user-using-cin) – Panagiotis Kanavos Jan 27 '17 at 16:20
  • 1
    Your issue seems related to powershell not the code. Using [SSH](https://developer.microsoft.com/en-us/windows/iot/Docs/SSH) works for me, you can have a try. – Rita Han Jan 30 '17 at 03:01
  • You are correct Rita, it also works for me using SSH. Thanks – Sebastian Jan 31 '17 at 08:30
  • @RitaHan-MSFT is this issue still exists on Powershell for Win10 IoT Core? I'm facing the same issue now. On SSH it works, but doesn't work on Powershell on IoT Core. Why such issue ? – Keshava GN Aug 10 '20 at 03:32
  • Not just powershell, it doesn't work on CMD as well , on the device. But works with SSH. Strange. @Sebastian were you able to run it on PS? – Keshava GN Aug 10 '20 at 03:34
  • @RitaHan-MSFT is there any other way to read from console in PS on IoT core? – Keshava GN Aug 10 '20 at 03:43

0 Answers0