Skip to content

Instantly share code, notes, and snippets.

@GZGavinZhao
Created March 20, 2022 00:30
Show Gist options
  • Save GZGavinZhao/4bad2b6802ba7461d92688fbdaba570f to your computer and use it in GitHub Desktop.
Save GZGavinZhao/4bad2b6802ba7461d92688fbdaba570f to your computer and use it in GitHub Desktop.
Fast I/O for competitive programming in Dart by calling getchar() in C.
import 'dart:ffi' as ffi;
typedef getchar_func = ffi.Int8 Function();
final dylib = ffi.DynamicLibrary.open("/usr/lib/libstdc++.so");
final int Function() getChar =
dylib.lookup<ffi.NativeFunction<getchar_func>>('getchar').asFunction();
void main() {
int input = getChar();
// There's no `char` in Dart. Use the following to convert your ASCII value
// into a [String]:
print(String.fromCharCode(input));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment