csv data reading

Hi everybody, ich wanna to read a csv data with 8 columns. the Program ask after a number and this number will be searched into the 2the column. if that is there, then the numbers in the 3,4,5,6,7,8the columns in the same row will be entered. So i need 7 object, for every column onece or???
that is my code meanwhile :

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "stdafx.h"
#include <vector>
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <fstream>
#include <sstream>
using namespace std;


template<class T> std::string toString(const T& t)
{
	std::ostringstream stream;
	stream << t;
	return stream.str();
}

template<class T> T fromString(const std::string& s)
{
	std::istringstream stream (s);
	T t;
	stream >> t;
	return t;
}

vector<string> &split(const string &s, char delim, vector<string> &elems) {
	stringstream ss(s);
	string item;
	while (getline(ss, item, delim)) {
		elems.push_back(item);
	}
	return elems;
}

vector<string> split(string s, char delim) {
	vector<string> elems;
	split(s, delim, elems);
	return elems;
}

vector<string> readData(const string &path)
{
	std::vector<std::string> lines;
	ifstream fin(path);
	std::string line;
	while(getline(fin, line))
	{
		lines.push_back(line);
	}
	return lines;
}
bool searchValue(vector<string> data, int column, string value, vector<string> &row)
{
	for(unsigned int i=1; i<data.size();i++)
	{
		row = split(data[i],';');
		string tc = row[column-1];
		if(tc.compare(value)==0)
			return true;
	}
	return false;
}
string replace(string str, char c, char newc)
{
	for(unsigned int i=0;i<str.size();i++)
	{
		if(str[i] == c)
			str[i] = newc;
	}
	return str;
}
int _tmain(int argc, _TCHAR* argv[])
{
	vector<string> data = readData("data.csv");
	vector<string>* row = new vector<string>();

	string number = "";
	while(number[0] != 'e')
	{
		cout << "Suche nach T[C]: ";
		cin >> number;
		bool wasfound = searchValue(data,2,number, *row);
		if(wasfound == true)
		{
			//TODO
			
		}
		else
			cout << "T[C] nicht gefunden " << endl;
	}
	return 0;
}


I have to say, that the 2th column my X-axis is and the columns 3-8 the Y-axis, so i have 6 different curves.
can you guys help me to solve that???

THX

Last edited on
Topic archived. No new replies allowed.