12

i m practising C++. i just add c++ files in XCode and write some string splitting functionality in it. After that i include that C++ file i.e. extension of .mm file in my AppDelegate file and call function from .h file of C++ class. But i found one static error in red line which is 'iostream' file not found . I used latest XCode version 4.5 and iOS 6.0. Please see screen shot of my error or xcode screen. enter image description here

I m tried to modify my code as per given link information but no success. :(

also i followed this link information as well, but result is same.

Thanks iHungry

9
  • Don't #include C++ code from a header that has to work in Objective-C. (Your problem could be that you are including StringSplit.h in a .m file somewhere.) Commented Jan 17, 2013 at 10:09
  • @Mankarse, sorry i m not getting you. I have to include C++ class file in Objective-C class. I do this but it throwing additional error to me . Commented Jan 17, 2013 at 10:14
  • If StringSplit.h is Objective-C++ (as opposed to Objective-C), you should only include it from .mm files and never .m files. Commented Jan 17, 2013 at 10:18
  • See my screenshot. I have have two files of C++ of one class .h and .mm files. I include StringSplit.h file in AppDelegate.m file. Commented Jan 17, 2013 at 10:20
  • Also i try to change extension of AppDelegate.m file to AppDelegate.mm but no success Commented Jan 17, 2013 at 10:21

1 Answer 1

11

Objective C having .m extensions for its implementation files. If you want to use C++ in Objective C it should have .mm extensions. you can include C++ header files in your .mm file. But if you want to include your C++ header files in your .h file, you need to check macro for that, like

#ifdef __cplus #include <iostream> #endif 

But, I haven't tried any functions by including C++ header file in .h file. Hope it helps.

Sign up to request clarification or add additional context in comments.

3 Comments

YOu can even use C files wiht .C
@AnoopVaidya, yes we can. But as per my requirement i have to do such functionality in C++.
What extra are you getting in C++ that is missing in the combination of C and Obj-C ? If I can help you :p

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.