3

I'm trying to output and C++ Array (int inverse[3]) using NSLog, but If I try this way:

NSLog([NSString stringWithFormat:@"%d", inverse]);

It just dont work, But if I try like this:

NSLog([NSString stringWithFormat:@"%d", inverse[0]]);

I get the right output. My objective is to get the whole array outputed.

Any ideas? Thanks

2 Answers 2

3

Use a for loop to print all the values.

for (int i=0; i<3; i++) {
    NSLog(@"%i", inverse[i]);
}

or:

NSLog(@"%i, %i, %i", inverse[0], inverse[1], inverse[2]);
Sign up to request clarification or add additional context in comments.

Comments

1

There is no need need to convert for string format conversion. You can print like these -

for ( int i=0; i<3; ++i )
    NSLog(@"%i", inverse[i]);

3 Comments

I want to print the whole array, and not just one int.
Anh.. THought it'll be an easier way to output this. Hate filling my code with 'unecessary' "fors" and "whiles". Thanks anyway :D
@markus: a function can't know the size of the array passed to it, so the syntax you want is just not possible in c++. you can write a function of your own that takes array and size, but nothing that can only take array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.