Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Acessing files in C++...
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Kuntzy




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Mon Feb 09, 2004 11:18 am   Post subject: (No 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;
   }
}
Andy




PostPosted: Mon Feb 09, 2004 5:03 pm   Post subject: (No 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
Kuntzy




PostPosted: Mon Feb 09, 2004 9:58 pm   Post subject: (No subject)

thanx ... Smile
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: