[Fixed] Writing UTF-8 text to SD card

Hello.
I have been testing my Mega 2560 with a Catalex MicroSD Card Adapter hooked up to the following pins (this information is probably not very useful as I have verified that the SD card works):
5V -> VCC
GND -> GND
SCK -> digital pin 52
MOSI -> digital pin 51
MISO -> digital pin 50
CS -> digital pin 53

I have uploaded CardInfo successfully, to get the usual messages on the serial monitor (I have tweaked the code, changing chipSelect to 53 instead of the usual 10):

Initializing SD card...Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (bytes): 4040163328
Volume size (Kbytes): 3945472
Volume size (Mbytes): 3853

Files found on the card (name, date and size in bytes): 
SYSTEM~1/     2018-04-10 20:57:44
  INDEXE~1      2018-04-10 20:57:44 76
  WPSETT~1.DAT  2018-04-10 21:11:16 12
TEST.TXT      2000-01-01 01:00:00 27

Moreover, I then uploaded ReadWrite (I have modified this program too as before, but also changed the test message to include "你好、こんにちは" ('Hello' in Chinese and Japanese):

This is the code after modification:

/*
  SD card read/write

 This example shows how to read and write data to and from an SD card file
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 53 (for MKRZero SD: SDCARD_SS_PIN)

 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 */

#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(53)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3. 你好、こんにちは");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  // nothing happens after setup
}

It works the same as before, except now in the serial monitor it outputs this:

Initializing SD card...initialization done.
Writing to test.txt...done.
test.txt:
testing 1, 2, 3. ????????

I know this is not an issue with the serial monitor. The serial monitor that comes with Arduino cannot handle non-ASCII text.

However, the problem lies in what was written to the text file. It has the same text that was in the text file: "testing 1, 2, 3. ????????", even though I had not made the program to write question marks.

My question is: How do I utilise the SD library to write UTF-8?

Sorry if the post was too long. This is my first time writing a post on the forums.


Many thanks.

Update: I've fixed it by including the line:

 #pragma execution_character_set("utf-8")

at the beginning of the sketch.