How can I use NSLog inside a CPP file?

Member
Posts: 249
Joined: 2008.10
Post: #1
Hi friends!

How can I use NSLog inside a CPP file? I mean, should I include or import any file? and How I send to it a string?

Thanks a lot for your help.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
By renaming to file to .mm, or using printf/cout instead. NSLog requires NSString, which requires an Objective-C compilation mode. The .mm extension allows you to compile as Objective-C++.
Quote this message in a reply
Member
Posts: 249
Joined: 2008.10
Post: #3
ThemsAllTook Wrote:By renaming to file to .mm, or using printf/cout instead. NSLog requires NSString, which requires an Objective-C compilation mode. The .mm extension allows you to compile as Objective-C++.

Thanks! I didn't know printf could work. Thanks a lot.

Edit: It seems only works on the simulator, but not when I launch the app on my iPhone. Do you all have the same problem? Any idea?
Thanks.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #4
riruilo Wrote:Edit: It seems only works on the simulator, but not when I launch the app on my iPhone. Do you all have the same problem? Any idea?
Thanks.

In what way does it not work on the iPhone?

Are you getting build errors, or are you not getting console output in Xcode as you expect?

Are you building for distribution or debug?

Are you launching the app from the iPhone, or launching the app from Xcode?

[edit] I ask because the only way I ever see console output from the iPhone in Xcode is build for debug and launch from Xcode. Otherwise you have to look at the console tab in the organizer to see the output.
Quote this message in a reply
Member
Posts: 249
Joined: 2008.10
Post: #5
AnotherJake Wrote:In what way does it not work on the iPhone?

Are you getting build errors, or are you not getting console output in Xcode as you expect?

Are you building for distribution or debug?

Are you launching the app from the iPhone, or launching the app from Xcode?

[edit] I ask because the only way I ever see console output from the iPhone in Xcode is build for debug and launch from Xcode. Otherwise you have to look at the console tab in the organizer to see the output.


OK. Now it is working perfectly, thanks a lot!
Quote this message in a reply
Post Reply