Print Method not working

So I have to write a program that picks up item ID, amount sold, amount remaining from a txt file:
501024BMU 895 743
455559SKK 764 234
706756EUU 687 730

And I have to be able to print an individual method using a method and print the array of information using the normal method.

For some reason it won't print. I assume it's because my read_list function didn
t save anything into the array.

Here's what I've written in my header file.

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
  class item
{
private:
	string id;
	int sold, remaining; 

public:	
	item ();
	void setidnum (string); 
	void setsold (int); 
	void setrem (int); 
	void print();
};

item::item()
{
	id = "";
	sold=0; 
	remaining = 0;

}

void item::setidnum (string idnum)
{
	id = idnum;
}

void item::setsold (int soldnum)
{
	sold = soldnum;
}

void item::setrem (int rem)
{
	remaining = rem; 
}

void item::print()
{
	cout << id << " " << sold << " " << remaining; 
}

void read_list(item arr[], ifstream& infile, int& x)
{
	string tempid;
	int tempsum, temprem;
	while (!infile.eof()) 
	{ 
		infile >> tempid; 
		arr[x].setidnum(tempid);
		infile >> tempsum; 
		arr[x].setsold(tempsum);
		infile >> temprem;
		arr[x].setrem(temprem);
		x++; 

	}
}



void print (item arr[],int ct)
{
	for (int x=0; x < ct; x++)
	{
		arr[x];
	}
}
Last edited on
1
2
3
4
for (int x=0; x < ct; x++)
{
	arr[x];
}
This code is the same as, for example:
1
2
3
4
for (int x=0; x < ct; x++)
{
	1;
}
You need to actually do something with value. Output it for example: std::cout << arr[x];
It keeps giving me an error, that no operator doesn't match the operands. Also I would assume that it'll repeat the print method I wrote out.
So, call print method on values instead of outputting them with operator<<. arr[x].print();
thank you so much... oh my god I was stuck on this for hours! I feel so dumb. lol. The answer was so obvious.
Topic archived. No new replies allowed.