Skip to content

Instantly share code, notes, and snippets.

@lemire
Created August 3, 2022 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lemire/ed0a1e29d16fade4cb71780818a9be34 to your computer and use it in GitHub Desktop.
Save lemire/ed0a1e29d16fade4cb71780818a9be34 to your computer and use it in GitHub Desktop.
#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