I want to encapsulate in/output into a function and call that function from main, but compiler shows me strange error once I did that
ifstream open_file(){
ifstream in;
string filename;
cout << "Plean Enter File Name: ";
cin >> filename;
in.open(filename.c_str());
while(true){
if (in.fail()){
cout << "Plean Enter File Name Again: ";
cin >> filename;
in.clear();
in.open(filename.c_str());
}
else
break;
}
return in;
}
call it from main
int main(){
ifstream in;
in = open_file();
return 0;
}
error(7 errors)
Description Resource Path Location Type
βstd::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits<char>]β is private Standford.Programming line 802, external location: /usr/include/c++/4.8/streambuf C/C++ Problem