-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimporting_csv_data.cpp
More file actions
46 lines (43 loc) · 1.22 KB
/
importing_csv_data.cpp
File metadata and controls
46 lines (43 loc) · 1.22 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
#include <iostream>
#include <fstream>
#include <string.h>
#include <vector>
#include <sstream>
#include <cstdlib>
using namespace std;
vector<vector<string> > vector_object(const char *file_name) {
ifstream fileName;
fileName.open(file_name);
string d;
vector <string> myVec;
vector<vector<string> > data;
while (!fileName.eof()) {
fileName >> d;
//getline(fileName, d); //use:if a cell has whitespace included.
stringstream ss(d);
vector <string> myVec;
string token;
while (getline(ss, token, ',')) {
myVec.push_back(token);
}
data.push_back(myVec);
}
data.erase(data.end() - 1);
return data;
}
int main() {
char file_name[10];
cout << "Enter the file name (without .csv)\n";
cin >> file_name;
strcat(file_name,".csv");
vector <vector <string> > data = vector_object(file_name);
cout << "Data present in " << file_name <<" are : \n";
string op;
for (int i = 0; i < data.size(); ++i) {
for(int j=0;j < data[0].size(); ++j){
cout << data[i][j] <<" ";
}
cout << endl;
}
return 0;
}