Can a text file be opened by passing thru a function?

Why does the string for the text file name print to the screen and not the contents of the text file?

//
// main.cpp
// GradeCalculator
//
//
//
#include<string>
#include <iostream>
#include <fstream>
#include <cmath>
#include<cstdlib>

using namespace std;
//-----------------------------function declarations
string GetStudentList();
string GetClassHours ();
string OpenStudentFile (string);
//-----------------------------create structures
struct Student_Info {
string FirstName;
string LastName;
int StudentID;
int GPA;
};
//-----------------------------main body
int main()
{
string File1;
cout << "Welcome to the GradeCaculator Deluxe." << endl;
cout <<"Enter the file name for the list of Students, including the extension::" << endl;
getline(cin, File1);
OpenStudentFile(File1);

//GetStudentList ();
return 0;
}//end main
string OpenStudentFile(string File1)
{
ifstream inputFile;
inputFile.open(File1.c_str());
if(!inputFile.is_open())
{
exit(EXIT_FAILURE);
}
cout << "\nThe file has been successfully opened for reading.\n";
cout << !inputFile << endl;
return File1;
}
Last edited on
Topic archived. No new replies allowed.