-
C++ (
http://www.daniweb.com/forums/forum8.html)
| psk | Jul 23rd, 2004 7:59 am | |
| Is ifs is a member function of ifstream class Hi all,
can anyone tell me whether ifs function is a member function of ifstream.
in the statements below the ifs has been used like ........
ifstream ifs( g_pSystemEnvironment->GetTotAlmCountFileName() );
ifs >> m_nNoOfTotalAlarm;
i am not able to understand the code. could anyone help me out of it.
Thanx in advance. |
| meabed | Jul 23rd, 2004 10:54 am | |
| Re: Is ifs is a member function of ifstream class 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;
} |
| Dave Sinkula | Jul 23rd, 2004 11:11 am | |
| Re: Is ifs is a member function of ifstream class Quote: Originally Posted by psk can anyone tell me whether ifs function is a member function of ifstream. ifstream ifs( g_pSystemEnvironment->GetTotAlmCountFileName() ); i am not able to understand the code. could anyone help me out of it. | Here ifs is not a function. It is an object of type ifstream. It is being instantiated using a parameterized constructor (passing the result of the g_pSystemEnvironment->GetTotAlmCountFileName function as the parameter) instead of the default constructor. |
| All times are GMT -4. The time now is 9:30 am. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC