Wednesday, 7 May 2014

day 45

using C++ I have discovered that it is possible to create a text file and write to it using a compiled program.

there is a directory of code located in a header file called <fstream> that allows you to be able to do this using lines of code like;
   int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile &lt;&lt; "Writing this to a file.\n";
  myfile.close();
  return 0;
}
when looking at this you can see that the line
 'ofstream myfile' will create the file you wish it to
 'myfile.open ("example.txt");' is creating the text document for you
 'myfile&lt;&lt;"Writing this to a file.\n";' is putting text in the file for you
 'myfile.close()' is closing the file for you

using these you can make a text file as well as write to it, using a program you have made.

No comments:

Post a Comment