Hi,
I have written a function which will open the file with the input name provided.Input name is in string format so while opening I am converting it using c_str().detail code below Plz let me know what is the wrong in code.
1 #include<iostream>
2 #include<fstream>
3 #include<string>
4 #include<stddef.h>
5 #include<cstddef>
6 #include<cstring>
7
8 using namespace std;
9
10 int main ()
11 {
12 string file1,file2;
13 string file3;
14
15 fstream OpenFile(string,ios_base::openmode);
16
17 cout << "Enter File Names"<<"\n";
18 getline(cin,file1);
19 getline(cin,file2);
20 getline(cin,file3);
21
22 ifstream INPUT1;
23 fstream INPUT2;
24 ofstream INPUT3;
25
26 INPUT1 = OpenFile(file1, ios::in | ios::binary);
27 INPUT2 = OpenFile(file2, ios::in);
28 INPUT3 = OpenFile (file3, ios::out);
29
30
31 INPUT1.close();
32 INPUT2.close();
33 INPUT3.close();
34
35 return 0;
36 }
37
38 fstream OpenFile (string filename, ios_base::openmode mode)
39 {
40 fstream file;
41
42 file.open (filename.c_str(), mode);
43 return file;
44 }