I guess you are programming under Windows, so you'll be able to use its conversion functions. Check out this FAQ entry then and scroll down to the "Correct Way". Ignore the stuff above it because it won't work with UTF-8. So if you want to write a UTF-8 file, you'll have to go through the following steps:
- Open the file in binary mode
- Convert the string you would like to write into Unicode (using MultiByteToWideChar with CP_ACP or better the real codepage, i.e. 1252)
- Convert the resulting Unicode string into UTF-8 (using WideCharToMultiByte with CP_UTF8)
- write this to the file

Alternatively you can check out Marius' article which explains how UTF8 works and then use the functions in his example.