If someone who knows this fairly well, id like to help along the way of doing this little project i have.
My boss at work generates a .csv file for call logs and im trying to build a program that will read the file, store data, and manipulate data as i need to and then display data.
I started the code but im hung up on a couple parts.
#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace std;
int main()
{
//opens the csv file.
ifstream gwfile;
gwfile.open("log.csv");
if(!gwfile) { // file couldn't be opened
cout << "FAILED: file could not be opened" << endl << "Press enter to close.";
cin.get();
return 0;
}else
cout << "SUCCESSFULLY opened file!\n";
cout << "-------------------------------------------------------------------------------\n\n\n";
longint SIZE = 0;
char data[SIZE];
cout << "This is data SIZE:" << data[SIZE] << endl;
//in the csv im trying to only read lines that start with the voice as those are only valid data we need.
//also i would like to display the headings in teh very first line
while( !gwfile.eof() ){
//This is where im trying to only accept the lines starting with "Voice"
if(data[SIZE] == "Voice"){
for(int i=0; i!='\n';i++;){
}
}
// getline(gwfile, data, '');
// cout << data[0];
}
return 0;
}
string line; // Also need to have #include <string> for this
while (!gwfile.eof())
{
getline(gwfile, line);
// Search "line" for what you're looking for
I'd use std::getline to read the entire line into a std::string. The parse the string by putting it into an ostringstream and extracting with getline delimited by ','
If the csv uses quotes to contain strings with non-delimiter commas you'll have to deal with that as well.
Within the lines there will be pieces of data that in an excell spread sheet it would be columns im adding up. With this be possible by storing them into strings?
What im thinking is i would need to store the data into arrays per each line and then adding up each element per array.
example:
csv would have
Fred,25,home,555-5555,current //this would be line 1
,36,work, 555-5555, current //this is line 2 but since the name field is blank i would like to skip this line.
Read an entire line.
Parse that line.
Apply "your" business logic based on what was read in, if you need to skip than skip, if you need to put what you've read into some container do that...