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: ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| 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;
} |
|
#2
| |||
| |||
| 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; |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |
Our Partners |