It's the newb again.

I have a lousy professor who won't even show us how to get started on importing a file (call it 'independent study'). Can anyone help me? I need to import the following data to produce a bar graph.


Here's the data. Can anyone help me to get started? The first line is a number indicating how many states in the file, the next line is the title and the following two lines are the x and y menu titles, after that it's the state name and the rainfall for each month.

Again, any help getting an idea (or even pointing me to the right website to go to would help too) would be a major help.


2
Average Precipatation
Month of the year
Rainfall in inches
Indianapolis
2.32
2.46
3.79
3.70
4.00
3.49
4.47
3.64
2.87
2.63
3.23
3.34
Miami
2.01
2.08
2.39
2.85
6.21
9.33
5.70
7.58
7.63
5.64
2.66
1.83

Recommended Answers

All 3 Replies

That was great, any idea how I can read two or more words in one line into a char[]?

In C look up fgets().

In C++ using C style strings look up getline(), which is an istream method, and because ifstreams and fstreams are also istreams you can also use it with an open ifstream.

ifstream if("myFileName.myFileExtension");
if(!fin)
{
  cout <<"Unable to open file by the name of myFileName" << endl;
  //do something here if you want
}
char w[80];
char terminatingChar = //whatever you want, defaults to newline char
fin.getline(w, 79, terminatingChar);

In C++ using STL style strings look up getline() as well, but the syntax is slightly different.

string s;
getline(fin, s, terminatyingChar);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.