Sabtu, 27 September 2014

Bahasa C++ Create New File -Write - Append .txt



MEMBUAT  FILE BARU DAN MENULIS PESAN:

#include <iostream>
#include <fstream>
using namespace std;

int writeFile();

int main()
{
    writeFile();
}

int writeFile ()
{
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile << "Writing this to a file.\n";
  myfile << "Writing this to a file.\n";
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}



 Append FILE

#include <fstream>



int main()
{
   ofstream ofile("example.txt", ios::app);
   if ( ofile )
   {
       ofile << "Dibuat di Jakarta by LP2MARAY";
       ofile.close();
   }
}

Tidak ada komentar:

Posting Komentar