Error C2784

Hello! I'm a first time poster, I apologize if this question is formatted incorrectly :)

I've looked over the forums and other websites regarding this error. i cannot "see" with my novice C++ eyes, what is wrong with my code. The errors that I saw that people were making, I don't see in my own code... I just need direction, as this is an assignment. The code is quite extensive (374 lines). I'm using windows 7.

The compiler has an issue with my generate_cities function. It specifically doesn't like lines 342 and 334 (lines 22 and 30 in code below) ... I tried including #include <string> which rid me of most of the C2784 errors, but not all. The program compiled until I included the function in question.

If the entire code is necessary to pin point where I went wrong, please let me know...

Brief Summary of This Function:

size - the number of times it writes to file the city names
numPerCity (size/2)- the number of times it writes each city name.

The user enters a even number. This function should print Reno and Seattle an equal number of times (so half in half), randomly.
So if the user enters 20, a list should pop up that has 20 lines, that say Reno or Seattle...each city appearing 10 times, randomly, in the list..



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
void generate_city(int size, int numPerCity)
{
	#include "city.h" //holds a char array "Reno", "Seattle"
	int b;
	int renoCount = 0;
	int seattleCount = 0;

	ifstream outputFile;

	outputFile.open ("city.txt");

	if (outputFile)
	{
		for (int i = 0; i < size; i++) 
		{
			b = rand () % 2;

			if (b == 0)
			
				while (renoCount < numPerCity )
				{
					outputFile << city_names [0] << endl;
					renoCount++;
				} 
			
			else if (b == 1)
		
				while (seattleCount < numPerCity )
				{
			        	outputFile << city_names [1] << endl;
					seattleCount++;
				} 
			
		}
	}	
	else
		cout << "ERROR: City file was not created successfully." << endl;
	
	outputFile.close();
}
Line 8:
ifstream outputFile; //ifstream is an INPUT file stream - means a file that is opened for READING

Lines 22 (and 30)
outputFile << city_names [0] << endl; //ERROR - you are trying to WRITE to an input file
Last edited on
Nothing like a fresh perspective! Thank you very much! I knew the problem would be simple and make me feel really small. I've been staring at this code for two days straight :) Thnx Again!
Topic archived. No new replies allowed.