How to read string and ints from a file and access them?

Okay, I have a .csv file and have a bunch of code that is supposed to take the items and allow access to them when I need to. The problem is I get a build error saying "no suitable conversion function from "std::string" to "int" exists". So how do I get around this cause I need to access them by putting them into an array.

Thanks for any help!

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
96

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

using namespace std;

struct Forecast {
	string day;
	int highTemp;
	int lowTemp;
	int humidity;
	int avgWind;
	string avgWindDir;
	int maxWind;
	string maxWindDir;
	double precip;
};

int main()
{
	Forecast data;
	data.day;
	data.highTemp;
	data.lowTemp;
	data.humidity;
	data.avgWind;
	data.avgWindDir;
	data.maxWind;
	data.maxWindDir;
	data.precip;

	const int arrayLength = 984;
	Forecast weatherD[arrayLength];

	ifstream Forecast;
	Forecast.open("DATABOULDER.csv");
	if (Forecast.fail())
	{
	}
	else 
	{
		string weather;
		int lineIndex = 0;
		while (getline(Forecast, weather, '\n'))
		{
			stringstream ss;
			ss << weather;
			int weatherIndex = 0;
			while (getline(ss, weather, ','))
			{
				if (weatherIndex == 0)
				{
					weatherD[lineIndex].day = weather;
				}
				else if (weatherIndex == 1)
				{
					weatherD[lineIndex].highTemp = weather;
				}
				else if (weatherIndex == 2)
				{
					weatherD[lineIndex].lowTemp = weather;
				}
				else if (weatherIndex == 3)
				{
					weatherD[lineIndex].humidity = weather;
				}
				else if (weatherIndex == 4)
				{
					weatherD[lineIndex].avgWind = weather;
				}
				else if (weatherIndex == 5)
				{
					weatherD[lineIndex].avgWindDir = weather;
				}
				else if (weatherIndex == 6)
				{
					weatherD[lineIndex].maxWind = weather;
				}
				else if (weatherIndex == 7)
				{
					weatherD[lineIndex].maxWindDir = weather;
				}
				else if (weatherIndex == 8)
				{
					weatherD[lineIndex].precip = weather;
				}
			}
		}
	}
    return 0;
}

Ok,
Undoubtedly the compiler is getting two references to "Forecast"
You have a struct Forecast and then you declare an ifstream Forecast.
If that isn't the problem, it's at least part of it.

Hope this helps!
Hello jlmccart01,

Do not start a second thread on the same question. It just it confusing for everyone. Better to stick with:
http://www.cplusplus.com/forum/beginner/198892/

Andy
Topic archived. No new replies allowed.