-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (50 loc) · 1.12 KB
/
Copy pathmain.cpp
File metadata and controls
60 lines (50 loc) · 1.12 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
//
// Read file csv
//
#include "csv-reader.h"
bool isDouble(const char *str)
{
char* endptr = 0;
strtod(str, &endptr);
return !((endptr == str));
}
int main(int argc, char* argv[])
{
ifstream infile;
string input = "input.csv";
string value;
int lineNo = 0;
int fieldCount = 0;
size_t lfFound;
double dataVar = 0.;
vector<string> lineCSV;
infile.open(input.c_str());
if (!infile)
{
cout << "Unable to open input."<< endl;
return 1;
}
int r = 0;
while (infile)
{
r = getCSVLine(infile, lineCSV);
cout << "Line number: " << ++lineNo << " Number of fields: " << lineCSV.size() << "\n";
for (int i = 0; i < lineCSV.size(); i++)
{
cout << " " << lineCSV[i] << " (is ";
if (!isDouble(lineCSV[i].c_str()))
cout << "not ";
cout << "double) ,";
if (isDouble(lineCSV[i].c_str())) cout << "|" << stod(lineCSV[i]) << "|, ";
}
cout << "\n";
if (!r)
{
cout << "Error - line " << lineNo << "\n\n";
return 0;
}
lineCSV.resize(0);
cout << "\n";
}
cout << "Everything OK!\n**==**==**==**==**==**==**==\n\n";
}