input the text and out put text is not working
Nov 24, 2013 at 6:09am UTC
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>
#include <iostream>
using namespace std;
typedef std::string String;
typedef std::vector<String> CSVRow;
typedef CSVRow::const_iterator CSVRowCI;
typedef std::vector<CSVRow> CSVDatabase;
typedef CSVDatabase::const_iterator CSVDatabaseCI;
void readCSV(std::istream &input, CSVDatabase &db);
void display(const CSVRow&);
void display(const CSVDatabase&);
int main(){
std::fstream file("file.csv" , std::ios::in);
if (!file.is_open()){
std::cout << "File not found!\n" ;
return 1;
}
CSVDatabase db;
readCSV(file, db);
display(db);
}
void readCSV(std::istream &input, CSVDatabase &db){
String csvLine;
// read every line from the stream
while ( std::getline(input, csvLine) ){
std::istringstream csvStream(csvLine);
CSVRow csvRow;
String csvCol;
// read every element from the line that is seperated by commas
// and put it into the vector or strings
while ( std::getline(csvStream, csvCol, ',' ) )
csvRow.push_back(csvCol);
for (int i = 1; i < body->GetRowCount(); i++) // i = 1 so we skip the header
{
CSVRow* row = body->GetRow(i);
for (int p = 0; p < row->GetFieldCount(); p++)
{
cout << row->GetField(p)->GetText() << "\t" ;
// calculation avg = (num1 + num2) / 2
// display average
}
cout << "\n" ;
}
there is something wrong in line 37 but idk how to fix it
An example of the file would (input)
15.1,Chico,17.4
34.4,Seattle,30.52
2.9,Portland,26.1
.5,Death Valley,1.1
This file could contain any number of entries.
Your output to the screen for the above file would be below.
The format of the output must match this example.
Please see the sample output file in case black bored doesnt format this correctly
City Total
----------------------------
Chico 32.5
Seattle 64.9
Portland 49.0
Death Vally 1.6
Topic archived. No new replies allowed.