Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- using namespace std;
- //Define functions.
- void input(ifstream& fin, char& fileName);
- int main()
- {
- ifstream fin;
- char fileName[20];
- input(fin, fileName);
- return 0;
- }
- void input(ifstream& fin, char& fileName)
- {
- cout << "Input file name: ";
- cin >> fileName;
- fin.open(fileName);
- if(fin.fail())
- {
- cout << "The file: " << fileName << " does not open." << endl;
- exit(1);
- }
- //return;
- }
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- using namespace std;
- //Define functions.
- void input(ifstream& fin, string& fileName);
- int main()
- {
- ifstream fin;
- string fileName;
- input(fin, fileName);
- return 0;
- }
- void input(ifstream& fin, string& fileName)
- {
- cout << "Input file name: ";
- cin >> fileName;
- fin.open(fileName.c_str());
- if(fin.fail())
- {
- cout << "The file: " << fileName << " does not open." << endl;
- exit(1);
- }
- //return;
- }
- void input(ifstream *fin, char *fileName);
- input(&fin, &fileName); // call
Add Comment
Please, Sign In to add comment