forked from roerohan/Miscellaneous
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommaSeperatedFile.cpp
More file actions
42 lines (41 loc) · 850 Bytes
/
commaSeperatedFile.cpp
File metadata and controls
42 lines (41 loc) · 850 Bytes
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
#include<iostream>
#include <sstream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
struct person
{
string name;
float weight;
string location;
string color;
};
//inside main
int main(void)
{
vector<person> people;
string wt;
person p;
ifstream in("data.txt");
while( getline(in,p.name,',') )
{
getline(in,wt,',');
p.weight = (float)atof(wt.c_str());
getline(in,p.location,',');
getline(in,p.color);
people.push_back(p);
}
//
// now just display all the data in the vector
//
vector<person>::iterator it = people.begin();
for(; it != people.end(); it++)
{
cout << (*it).name << ", "
<< (*it).weight << ", "
<< (*it).location << ", "
<< (*it).color << "\n";
}
return 0;
}