getchar, scanf, getch, these will block if the user does not input. What should I do if I don’t want to block?
I searched online and found that fcntl can be used in Linux, but not in Windows (you can use GetAsyncKeyState to check the keys, but you cannot know whether stdin has content)
伊谢尔伦2017-06-17 09:18:16
There is ioctl
on windwos that can be implemented, but this is just setting the attributes of the file descriptor. For non-blocking input, you still need to configure the corresponding API
I found an example and I’m not sure if it’s what you want. The file descriptors used by socket and IO are the same
set nonblock
These things can all be found on Google. .