Hi, I'm just learning c++ and really need your help to program as stated by topic.
Basically, I have a text file called 'example.txt', and within this file, there are more .txt filenames (e.g. 'abc.txt', '123.txt').
=========================================
For example: // following are contents within 'example.txt'
//contain grid-areas
abc.txt
//contain results
123.txt
=========================================
How do I go about reading in the contents of 'example.txt' and the program upon reading that there are more filenames, proceed to further access them and read them in?
So far, I know how to read in a file using the following codes. But I'm stuck at how to further read the other .txt files in the main file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <fstream>
#include <iostream>
#include <string>
int main (const int argc, const char **argv)
{
std::ifstream file;
file.open ("example.txt");
if (!file.is_open ())
{
std::cerr << "Error opening file: " << filename << std::endl;
return 1;
}
std::string line;
while (file.good ())
{
std::getline (file, line);
std::cout << line << std::endl;
}
file.close ();
return 0;
}
|
Can anyone help me? Please advise, thank you!!