Created
March 20, 2022 00:30
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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