#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string location = "";
cout << "Enter the location of the file: ";
cin >> location;
ifstream reader(location);
while (!reader.good())
{
reader.close();
reader.clear();
cout << "Enter the location of the file: ";
cin >> location;
ifstream reader(location);
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxzdHJpbmc+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgoKCmludCBtYWluKCkKewogICBzdHJpbmcgbG9jYXRpb24gPSAiIjsKICAgY291dCA8PCAiRW50ZXIgdGhlIGxvY2F0aW9uIG9mIHRoZSBmaWxlOiAiOyAKICAgY2luID4+IGxvY2F0aW9uOwogICBpZnN0cmVhbSByZWFkZXIobG9jYXRpb24pOwogICAKICAgd2hpbGUgKCFyZWFkZXIuZ29vZCgpKSAgIAogICB7CiAgICAgIHJlYWRlci5jbG9zZSgpOwogICAgICByZWFkZXIuY2xlYXIoKTsKICAgICAgY291dCA8PCAiRW50ZXIgdGhlIGxvY2F0aW9uIG9mIHRoZSBmaWxlOiAiOyAKICAgICAgY2luID4+IGxvY2F0aW9uOwogICAgICBpZnN0cmVhbSByZWFkZXIobG9jYXRpb24pOwogICB9Cgp9Cg==
prog.cpp: In function 'int main()':
prog.cpp:14:28: error: no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(std::string&)'
ifstream reader(location);
^
prog.cpp:14:28: note: candidates are:
In file included from prog.cpp:3:0:
/usr/include/c++/4.9/fstream:470:7: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]
basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
^
/usr/include/c++/4.9/fstream:470:7: note: no known conversion for argument 1 from 'std::string {aka std::basic_string<char>}' to 'const char*'
/usr/include/c++/4.9/fstream:456:7: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char; _Traits = std::char_traits<char>]
basic_ifstream() : __istream_type(), _M_filebuf()
^
/usr/include/c++/4.9/fstream:456:7: note: candidate expects 0 arguments, 1 provided
/usr/include/c++/4.9/fstream:430:11: note: std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)
class basic_ifstream : public basic_istream<_CharT, _Traits>
^
/usr/include/c++/4.9/fstream:430:11: note: no known conversion for argument 1 from 'std::string {aka std::basic_string<char>}' to 'const std::basic_ifstream<char>&'
prog.cpp:22:31: error: no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(std::string&)'
ifstream reader(location);
^
prog.cpp:22:31: note: candidates are:
In file included from prog.cpp:3:0:
/usr/include/c++/4.9/fstream:470:7: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]
basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
^
/usr/include/c++/4.9/fstream:470:7: note: no known conversion for argument 1 from 'std::string {aka std::basic_string<char>}' to 'const char*'
/usr/include/c++/4.9/fstream:456:7: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char; _Traits = std::char_traits<char>]
basic_ifstream() : __istream_type(), _M_filebuf()
^
/usr/include/c++/4.9/fstream:456:7: note: candidate expects 0 arguments, 1 provided
/usr/include/c++/4.9/fstream:430:11: note: std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)
class basic_ifstream : public basic_istream<_CharT, _Traits>
^
/usr/include/c++/4.9/fstream:430:11: note: no known conversion for argument 1 from 'std::string {aka std::basic_string<char>}' to 'const std::basic_ifstream<char>&'