How do I print the contents of an array ?

I'm trying to print out the contentes of my array in order to make sure I'm correctly filling up my array. How can I get the contents to display out on the console ? I have the following function reading numbers from a text file and if I have it set up correctly, they are being seeded into the array. How would I print them out in a main function ?


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
void donationReader(int d[])
{


	int i =0;
	int numberOfDonors = 0;

	ifstream inFile; //Declare the input file stream
	inFile.open("donations.txt"); //Opening the file
	
	
	do{
		inFile>>d[i];// seeding the numbers into the array :D

	}while(!inFile.eof()); //Keep seeding the array with numbers until the end of the file.


	if(!inFile){
		cout << "Unable to open the file donations.txt";
		exit(1); // shut dowm the program if possble
	}

	inFile.close();// Closes the file

	
}


I've tried to iterate with this bit of code but nothing prints on the screen.


1
2
3
4
 for (int i=0; i>100;i++)
	 {
	 cout<<d[i]<<endl;
	 }

i>100

Look here. ;)
AWSOME !!!

Okay, thanks now I have a new problem. I'm getting a bunch of weird numbers to print out and not the number from the text file :O
1
2
3
4
	do{
		inFile>>d[i];// seeding the numbers into the array :D

	}while(!inFile.eof()); //Keep seeding the array with numbers until the end of the file. 

i doesn't change. Try a for loop here.

1
2
3
4
if(!inFile){
	cout << "Unable to open the file donations.txt";
	exit(1); // shut dowm the program if possble
}

It's probably better to put this just after inFile.open()
Topic archived. No new replies allowed.