Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print C++ array in Objective-C "NSLog"

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

like image 530
markus Avatar asked May 01 '26 03:05

markus


2 Answers

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]);
like image 191
zaph Avatar answered May 03 '26 18:05

zaph


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]);
like image 35
Mahesh Avatar answered May 03 '26 18:05

Mahesh