# Include <iostream>
# Include <vector>
# Include <fstream>
# Include <string>
Using namespace STD;
/* Store each row in the file in each element in the vector */
Int filetovector (string filename, vector <string> & SVEC)
{
Ifstream infile (filename. c_str ());
If (! Infile) return 1; // file loading failed
String S;
While (Getline (infile, S) // read data row by row and press it into the vector.
{
SVEC. push_back (s );
}
Infile. Close ();
If (infile. EOF () return 4; // indicates the end of the object.
If (infile. Bad () return 2; // System Error
If (infile. Fail () return 3; // read failed
}
Int main ()
{
Vector <string> SVEC;
String filename, S;
Cout <"Enter filename:" <Endl;
Cin> filename;
Switch (filetovector (filename, SVEC ))
{
Case 1:
Cout <"file loading failed" <FILENAME <Endl;
Break;
Case 2:
Cout <"system error" <Endl;
Break;
Case 3:
Cout <"read failed" <Endl;
Break;
Default:
Break;
}
Cout <"vector:" <Endl;
// Print the content in the vector
For (vector <string >:: iterator iter = SVEC. Begin (); iter! = SVEC. End (); ++ ITER)
{
Cout <* ITER <Endl;
}
Return 0;
}