The easiest way to write the word David inside a file is to simply use File.WriteAllText. This will create the file if it does not exist and overwrite it if it exists.
System.IO.File.WriteAllText("C:\folder\myfile.txt", "David");
But note that this is C# (as per the title of your question) and not C++ (as per the sample code that you posted).