how to read csv files within .txt

Hi all,

I have just started learning c++.
I got a simple question, is it possible to open a batch of csv files within a text file format? or is there a way to open the csv files in loop?
Let's say, I have abc.txt and inside contains
123.csv
234.csv
345.csv
456.csv
567.csv
678.csv
734.csv
8qs.csv
9xz.csv
10x.csv

I do know how to open the text file using the ifstream but it just reads the above data.
I guess you only have to split the text you've read with ifstream and then execute it by system(/*blah*/);. To use this feature, you have to include #include <stdlib.h>
Last edited on
Well you need to read in the file names from your abc.txt into a std::string variable and use that to open the csv file:
1
2
3
4
5
6
7
std::string csv_file_name; // read this in from abc.txt

std::ifstream csv;

csv.open(csv_file_name.c_str());

// now read the csv file whose name you read from abc.txt 
thanks for the kind help.. really appreciate. :)
1
2
3
4
5
6
fstream manifest( "abc.txt" );
string csv_filename;
while( getline( manifest, csv_filename ) ) {
    fstream fin( csv_filename.c_str() );
    // process data from fin
}
Last edited on
Topic archived. No new replies allowed.