CSV file to array/map - Urgent Plz

Hello,

I am new to programming and I am trying to open up a .csv file that is a large set of data with many values seperated each by a semi-colon. I would like to open this file and then run a 'for loop' on this set of data to find the minimum and maximum values. I already successfully ran the for loop for a random array of variables to test it. I have been searching for days trying to open this data and store into a map or array, so any help would be greatly appreciated.

I have also been trying to understand the differences between a map and array, but it's still not exactly clear to me. Sorry for these general questions.

Ryan

Here is what I've programmed so far just using a random array of variables, that I would like to replace with a large matrix of values from this .csv file:

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
#include <iostream>


using namespace std;

int main()
{
	int pmin = 20;
	int pmax = 50;
	double mndiff, mxdiff;
	double mn, mx;
	const int n = 10;
	double p[n] = { 2.6, 63.78, 23.41, 11.22, 30.41, 23.88, 52.1, 42.96, 33.44, 1.25 };


	for (int i = 0; i < 10; i++)

		mn = p[0];
		mx = p[0];

		for (int i = 1; i < 10; i++)
		{
			if (mn>p[i])
			{
				mn = p[i];
			}
			else if (mx < p[i])
			{
				mx = p[i];
			}
		}
			
		if (mn < pmin)
		{
			  mndiff = pmin - mn;
		}

		if (mx > pmax)
		{
			  mxdiff = mx - pmax;	
		}
		

		cout << "Max pressure is: " << mx << endl;
		cout << "Min pressure is: " << mn << endl;
		cout << "Max pressure is over constraint by: " << mxdiff << endl;
		cout << "Min pressure is under constraint by: " << mndiff << endl;
		
	cin.get();
	return 0;
}



Last edited on
There are thousands of duplicates of this question on the internet and even these forums, I've seen several just this week, and you say you've found nothing from searching for days?

http://www.cplusplus.com/search.do?q=CSV

A map is nothing like an array, it is an associative container that associates keys with values.
There are thousands of duplicates of this question on the internet and even these forums, I've seen several just this week, and you say you've found nothing from searching for days?


Perhaps I have come across a possible solution, but haven't recognized it. My level of programming is very basic, so I'm still trying to make sense out of everything.

A map is nothing like an array, it is an associative container that associates keys with values.


Okay, but both a map and array can store 2d data correct?
Last edited on
I said "a map a nothing like an array", so no, a map cannot store 2D data.

Here's what I think you need: an array/vector for the column headers, an array/vector for the row names, and an array/vector for the 2D data.
both a map and array can store 2d data correct?

You can create 2d arrays.

maps are a different animal. A map has a key value. The key is 1d, but there is no reason the object that each map entry stores can't be 2d. Not clear from the data you posted that this is the best approach.

Do you know the maximum number of columns in advance?

A vector of vectors might be a better fit.


Topic archived. No new replies allowed.