Hello all,

I'm getting an error in the following code, and I can't figure out why exactly. Error is as follows:

no match for 'operator>>' in 'scoresIn >> scoresArray'

this is at line 28 on the code below.

I'm trying to bring in some data from a text file into and array and just can't seem to make it happen. I've looked at examples and they all state that you can basically use the ifstream variable as a cin. Using this approach doesn't work for me. Must I use a for loop? the example code is as follows.

#include<fstream>
#include<iostream>
using namespace std;

int main ( )
{
	//char opposingTeam [25];
	const int initalize = 25;
	int count = 1, count1, scores;
	int scoresArray [initalize];
	ifstream scoresIn;

	for (int i = 0; i < initalize; i++) // sets scoresArray to 0
	    {
	        scoresArray[i] = 0;
		}
	for (int i = 0; i < initalize; i++) // checks that they are zero via cout.
	{
			cout << scoresArray[i] << " ";
	}

		scoresIn.open("scores.txt");

	if (!scoresIn.fail( ))
	{
		cout << "Success!\n";

		scoresIn >> scoresArray;
	}
		//scoresIn >> scoresArray[scores];


	while (!scoresIn.eof( ))
		{
			cout << "UF game #: " << count << " score: " << scoresArray [initalize] << endl;
			count++;
			scoresIn >> scoresArray [initalize];

		}
	    scoresIn.close();
	    cout << scores << endl;
	    cout << scoresArray [1] << endl;

Almost forgot, i'm using MinGW in Eclipse indigo

If the data from the text file is needed just let me know.

thanks alot for the help.

rcowboy

Arrr matey, the error of ye' ways be in lines #35 & #37. Yarrrr.

Edited 5 Years Ago by Clinton Portis: you are trying to put everything in array[25]

Well, I played with it some more, and still can't get it to work. Let me ask this question. I think the text file is being brought into the array, but is it being overwritten? I don't think this is happening because when I output to the screen at the very bottom I still get 0's from the array, so its still not bringing data in from the text file. I'm about to give up on this, and change my logic and go some other route. Should I get rid of the while loop, and go with a for loop? I'll try that and see what happens.

scoresIn >> scoresArray [initalize];

This was an attempt to just try and shove the data into the array. Guess it doesn't work. lol.

I'll try a for loop and see what it does.

intitialize = 25. which means your array is set to [0] thru [24]. in your code, scorsin >> scoresArray[initialize] is like saying scorsin >> scoresArray[25].... which is out of bounds of your array. you are attempting to access memory that isn't allocated to you. additionally, you are trying to read your entire text file into a single element of your array (array[25]). So, to summarize, you are attempting to read an entire text file into a single element of an array... that isn't even allocated to you. Solution: use a counter to step through the array everytime you make a read operation from your text file. Then, increment your counter each subsequent loop through your array. Finally, ensure your counter stays less than 25, because 25 will take you out of bounds of ye' array.

Edited 5 Years Ago by Clinton Portis: n/a

Mr. Portis,

I want to thank you. You put me on the right track. I've got it working with the following code.

for (int i = 0; i < initialize; i++) // sets scores into scores array
	{
		scoresIn >> scoresArray [i];
		count++;
		cout << count << " ";
		cout << scoresArray [i] << " ";
	}

Of course the couts are to the screen. Thats so I can see whats going on in the array. I have since seperated the array into odd and even #'s and plan on doing some outputs to another text file. Anyways thanks for the help. Hopefully the rest of it will go smoothly.

Oh by the way Mr. Portis, I'll have you know I only live a few ye miles from ye mommas purple house. Arr..

rcowboy

Edited 5 Years Ago by rcowboy: n/a

Comments
My mom lives in a yellow house.
This article has been dead for over six months. Start a new discussion instead.