开发者

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

I'm trying to output and C++开发者_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


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]);


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]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜