C++/OOP

Advertisement


Question
can u tel me the errors in the following statements..please

1.ifstream.infile("DATA");
2.infile.open(argc);
3.finout.open(file:ios::in|ios::out|ios::ate);
4.infile.open(argc);

hope for ue early reply...
Thanking You,
Rikin

Answer
Dear Rikin!

1. In the first statement , ifstream is a class where as infile    is an object associated with ifstream class( it will invoke the constructor for ifstream class in order to open a file in input mode !) so the statement should be used like this.
  ifstream  infile("DATA");

2. As we know very well in the command line argument the variable 'argc ' is as integer used to hold the number of arguments passed to main() , where as the member function
open() expects a string  to open a file  , not an integer !

3. The general format of 3rd statement is   stream_object.open("filename" , mode);

so the given instruction finout.open(file:ios::in ....) should have to be corrected as
finout.open(file , ios::in|ios::out|ios::ate);

4.Refer 2nd point !

Regards !
Prince M. Premnath.
-Happy Programming !

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise

Years of research in C/C++ Will bring you all facts regarding , OOPS , SVGA , MOUSE , BIOS , IVT , Feel free to query me :-)

Experience

More than 5 years

Education/Credentials
MCA

©2016 About.com. All rights reserved.