How to display from a class?

Pages: 12
Line 8: You're trying to access mArray[i], but you haven't defined i.

Your code for writing the output should look like my Display() function with the difference that you're writing to output rather than cout.

In fact, you can generalize Display to write to any ostream.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void dCoords::Display (ostream & os) const
{   for (int i = 0; i < ARRAY_SIZE; i++)     //  use max array size
	{   os << mArray[i].x << "," << mArray[i].y << endl;
	}	
}

void dCoords::Output () const
{   ofstream output ("output_1.txt");
	if (!output)
	{   cout << "Cannot open file";
		exit(1);
	}
	output << "Coordinates are:" << endl;
	Display (output); 	
	output.close();
}
	
int main ()
{   dCoords obj;
    
    obj.LoadFile (); 
    obj.Display (cout);
    obj.Output ();
}


Thanks AbstractionAnon you've been a massive help and I cannot thank you enough :)
SCB3 wrote:
Seriously? I'm was looking for some help and may have misworded or not fully understood what was expected, there's no need to be so negative, especially since this is all still quite new to me


Well, at least you could pay attention to this part:

TheIdeasMan wrote:
@OP if that is not the case, then think seriously about how you ask your question, and what information you provide. If you want help, then be helpful yourself.


Also, think about it from our Point Of View: We have a lot of trolls here, this is just the sort of stuff they deliver all the time, along with denial.

AbstractionAnon was very helpful, but it took about 20 posts to find out what is was you were trying to do.

You this is quite new to you, but you have been a member here since Mar 2015 and have 83 posts - so you aren't really new.
Topic archived. No new replies allowed.
Pages: 12