Skip to content

Instantly share code, notes, and snippets.

@bredmor
Created November 12, 2021 20:40
Show Gist options
  • Save bredmor/206a36e7ae60bdf0f5a19e94af084641 to your computer and use it in GitHub Desktop.
Save bredmor/206a36e7ae60bdf0f5a19e94af084641 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <windows.h>
#define INPUT_MAX 255
void main()
{
wchar_t wstr[INPUT_MAX];
char mb_str[INPUT_MAX * 3 + 1];
unsigned long readln;
SetConsoleOutputCP(CP_UTF8);
SetConsoleCP(CP_UTF8);
void *console = GetStdHandle(STD_INPUT_HANDLE);
ReadConsole(console, wstr, INPUT_MAX, &readln, NULL);
int size = WideCharToMultiByte(CP_UTF8, 0, wstr, readln, mb_str, sizeof(mb_str), NULL, NULL);
mb_str[size] = 0;
printf("echo: %s\n", mb_str);
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment