Possible Duplicate:
Manipulate Input File Stream
C++ How to overload cin to read file
I was trying the following with operator overload..
struct myself
{
string myname;
}
istream &operator>> (istream &stream, myself &mm)
{
cout << "Enter my name:";
stream >> mm.myname;
return stream;
}
int main()
{
myself mm;
cin >> mm;
cout << mm.myname;
}
and its work, able to echo out what i actually type.
Now i trying to proceed with
cout << "Enter file name to read: ";
//assume user type myfile.txt
cin >> readFile;
How do i overload my cin to make it read file.
Consider my file is something like
sometextdocument.txt that contains data like
Map2D, [3, 2]
Dot3D, [25, -69, -33], [-2, -41, 58]
Map3D, [6, 9, -50]
Map2D, [3, 2]
Dot3D, [7, -12, 3], [9, 13, 68]
Map3D, [6, 9, 5]
Map2D, [3, 2]
Dot3D, [70, -120, -3], [-29, 1, 268]
Dot3D, [7, 12, 3], [-9, 13, 68]
Map3D, [1, 3, 8]
Dot2D, [5, 7], [3, 8]
And then i wanna cout << "Number of records read: " << number << endl;
then do a return stream, how do i overload it to work as cin read a file