943,879 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 6170
  • C++ RSS
Jul 23rd, 2004
0

Is ifs is a member function of ifstream class

Expand Post »
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.
psk
Reputation Points: 10
Solved Threads: 0
Newbie Poster
psk is offline Offline
1 posts
since Jul 2004
Jul 23rd, 2004
0

Re: Is ifs is a member function of ifstream class

look at this example ...
C++ Syntax (Toggle Plain Text)
  1. #include <fstream> β€’ <fstream> header file
  2. using namespace std; – Use ifstream for input
  3. int main() – Use ofstream for output
  4. {
  5. ifstream ifs;
  6. ifs.open(β€œin.txtβ€?); β€’ Other methods
  7. ofstream ofs(β€œout.txtβ€?); – open, is_open, close
  8. if (ifs.is_open() && – getline
  9. ofs.is_open()){ – seekg, seekp
  10. int i; β€’ File modes
  11. ifs >> i; – in, out, ate, app, trunc, binary
  12. ofs << i;
  13. }
  14. ifs.close();
  15. ofs.close();
  16. return 0;
  17. }
--------------------------------------------------------------------------------
C++ Syntax (Toggle Plain Text)
  1. #include <iostream> β€’ <sstream> header file
  2. #include <fstream> – Use istringstream for input
  3. #include <sstream> – Use ostringstream for output
  4. using namespace std;
  5. int main() { β€’ Useful for scanning input
  6. ifstream ifs(β€œin.txtβ€?); – Get a line from file into string
  7. if (ifs.is_open()) – Wrap string in a stream
  8. {string line1, word1; – Pull words off the stream
  9. getline(ifs, line1); β€’ Useful for formatting output
  10. istringstream iss(line1); – Use string as format buffer
  11. iss >> word1; – Wrap string in a stream
  12. cout << word1 << endl; – Push formatted values into stream
  13. } – Output formatted string to file
  14. return 0;
  15. }
Team Colleague
Reputation Points: 55
Solved Threads: 3
Junior Poster
meabed is offline Offline
139 posts
since May 2004
Jul 23rd, 2004
0

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.
C++ Syntax (Toggle Plain Text)
  1. 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.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Saving a file using C++
Next Thread in C++ Forum Timeline: VC++:convert File IStream to hex and store...?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC