RSS Forums RSS
Please support our C++ advertiser: Programming Forums

Is ifs is a member function of ifstream class

Join Date: May 2004
Location: Egypt - Cairo
Posts: 130
Reputation: meabed is on a distinguished road 
Rep Power: 5
Solved Threads: 2
Colleague
meabed's Avatar
meabed meabed is offline Offline
Junior Poster

Re: Is ifs is a member function of ifstream class

  #2  
Jul 23rd, 2004
look at this example ...
#include <fstream>            β€’ <fstream> header file
using namespace std;         – Use ifstream for input
int main()                         – Use ofstream for output
{
ifstream ifs;                      
ifs.open(β€œin.txtβ€?);              β€’ Other methods 
ofstream ofs(β€œout.txtβ€?);     – open, is_open, close    
if (ifs.is_open() &&            – getline
ofs.is_open()){                – seekg, seekp  
int i;                              β€’ File modes
ifs >> i;                          – in, out, ate, app, trunc, binary
ofs << i; 
}
ifs.close();
 ofs.close();
return 0;
}
--------------------------------------------------------------------------------
#include <iostream>         β€’ <sstream> header file
#include <fstream>          – Use istringstream for input
#include <sstream>          – Use ostringstream for output
using namespace std;       
int main() {                      β€’ Useful for scanning input
ifstream ifs(β€œin.txtβ€?);          – Get a line from file into string
if (ifs.is_open())                – Wrap string in a stream
{string line1, word1;          – Pull words off the stream
getline(ifs, line1);              β€’ Useful for formatting output
istringstream iss(line1);      – Use string as format buffer
iss >> word1;                   – Wrap string in a stream
cout << word1 << endl;     – Push formatted values into stream
}                                    – Output formatted string to file
return 0;
}
Real Eyes Realize Real Lies
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:03 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC