Ok, I have a problem getting an array or string to print. Using cout gives me the memory address of the beginning of the string or array.

Code:

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

int main(void){
int iArray[5] = {5,3,2,1,8};

cout<< iArray;

return 0;

}

I want a command that outputs the array as a whole i.e. 53218 not 0x86fdd0. Hopefully not using a loop.
I appologize for the lack of clarity in my previous post.

07-09-2003

Speedy5

Right now, you're printing the pointer to the array. You cannot print the whole array with a standard function/something. You'll have to code it yourself with a loop:

Code:

// prints the whole array, with no delimeter
for (int i = 0; i < 5; i++)
cout << iArray[i];

07-09-2003

joshdick

If you don't want to see the loop or code one every time you print your array, you could write a function that accepts the array and the number of members in it and prints it the way you want it. Something like: