Computer Science Canada

Acessing files in C++...

Author:  Kuntzy [ Tue Dec 30, 2003 11:45 am ]
Post subject:  Acessing files in C++...

How do you access a file, write to ut and read from it. Can erase files, and create new ones?

Author:  wtd [ Mon Feb 09, 2004 11:18 am ]
Post subject: 

Try googling for information on using the iostream libraries.

code:
// Not tested

#include <fstream>
#include <string>

int main(int argc, char ** argv)
{
   std::ifstream input_file("input.txt"); // object for an input file stream
   std::ofstream output_file("output.dat"); // object for an output file stream
   std::string temp;

   while (input_file.good())
   {
      input_file >> temp;
      output_file << temp;
   }
}

Author:  Andy [ Mon Feb 09, 2004 5:03 pm ]
Post subject: 

using ios::append lets u continue to write onto the file and using ios::nocreate will not create the file if its not there then u can use is_open to check whether if the file exists

Author:  Kuntzy [ Mon Feb 09, 2004 9:58 pm ]
Post subject: 

thanx ... Smile


: