Print to Console from *.csv file

I was able to correctly parse an *.xml to *.csv. Now, I am attempting to print the contents of the *.csv in tabular format to console screen. Having problems achieving this. Any ideas?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void XML_Parser::printFromFile() {

	std::ifstream file;

	file.open("test.csv");

	std::string line;
	std::string value;
	std::string temp;
	
	if (file)
		//while (getline(file, line)) {
		while(file.good()){

			getline(file, value, ',');
			std::cout << std::setw(10);
			std::cout << value;
			
		}
	else
		std::cout << "Failed to open File" << std::endl;
}



Current output looks like this http://imgur.com/aixDdZB
Last edited on
You could use a stringstream to extract each value from the line.
1
2
    istringstream ss(line);
    while ( getline(ss, value, ',') 

etc.

That will need #include <iostream>

Topic archived. No new replies allowed.