IT Community - Software Programming, Web Development and Technical Support

C++ Input/Output with files

This is a discussion on C++ Input/Output with files within the C and C++ Programming forums, part of the Software Development category; Input/Output with files: C++ provides the following classes to perform output and input of characters to/from files: ofstream: ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 12-21-2008, 08:57 PM
smith21 smith21 is offline
D-Web Trainee
 
Join Date: Dec 2008
Posts: 13
smith21 is on a distinguished road
Default C++ Input/Output with files

Input/Output with files:

C++ provides the following classes to perform output and input of characters to/from files:

ofstream: Stream class to write on files
ifstream: Stream class to read from files
fstream: Stream class to both read and write from/to files.
These classes are derived directly or indirectly from the classes istream, and ostream. We have already used objects whose types were these classes: cin is an object of class istream and cout is an object of class ostream. Therfore, we have already been using classes that are related to our file streams. And in fact, we can use our file streams the same way we are already used to use cin and cout, with the only difference that we have to associate these streams with physical files. Let's see an example:

Code:
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 12-22-2008, 08:26 PM
hkp819 hkp819 is offline
D-Web Trainee
 
Join Date: Dec 2008
Posts: 43
hkp819 is on a distinguished road
Default Re: C++ Input/Output with files

I agree with you...
you have given the header file
#include <iostream>
#include <fstream>
using namespace std;

here we can give the header file like that also:
#include<iostram>
#include<ifstream>
#include<ofstream>
using namespace std;
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Templates for Input/Output in J2ME? dchips13 J2ME 3 09-30-2008 04:53 AM
get a URL from cmd line input. amansundar Java Programming 6 11-20-2007 02:27 AM
How do I validate the form input before sending it to the server? itbarota HTML, CSS and Javascript Coding Techniques 1 09-13-2007 02:57 AM
Trace files and Log Files in Unix vigneshgets Operating Systems 0 08-01-2007 05:18 AM
Java:Tutorial - User Input pranky Java Programming 0 02-24-2007 12:52 AM


All times are GMT -7. The time now is 01:44 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0