Created
August 3, 2022 21:15
-
-
Save lemire/ed0a1e29d16fade4cb71780818a9be34 to your computer and use it in GitHub Desktop.
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
#include <fstream> | |
#include <iostream> | |
int main() { | |
char16_t output_buffer[] = u"hello world"; | |
size_t len = sizeof(output_buffer) / sizeof(char16_t); | |
std::ofstream out("output.ut16.txt", std::ios::binary | std::ios::trunc); | |
out.write(reinterpret_cast<char *>(output_buffer), len * sizeof(char16_t)); | |
std::cout << "wrote " << out.tellp() << " bytes" << std::endl; | |
out.close(); | |
if (!out) { | |
std::cerr << "Something is wrong with the file IO." << std::endl; | |
return EXIT_FAILURE; | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment