Read Files

Looking for help on this assignment cause i'm new to c++. Can anyone help me out with figuring this out? how to read multiples files with void prodecure? i'm getting confused in ifstream part. thanks for your help and i'm sorry for my broken eng

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  #include <bits/stdc++.h>
using namespace std;

void readFile(string file_name) {
string line;
ifstream myfile;

if (myfile.is_open())
{
while ( getline (myfile,line) )
{
cout << line << '\n';

}
myfile.close();

}

else
{
cout << "This file can't be opened";
}
}

int main () {
string file1 = "a.txt";
string file2 = "b.txt";
string file3 = "c.txt";
readFile(file1);
readFile(file2);
readFile(file3);
}
Last edited on
It should be just
ifstream myfile(file_name);

Or perhaps this if your compiler is older.
ifstream myfile(file_name.c_str());
thank you so much for your help, now i know what should i do :)
Topic archived. No new replies allowed.