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

Community
  • 1
  • 1
Tirth
  • 7,801
  • 9
  • 55
  • 88
  • 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.) – Mankarse Jan 17 '13 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 . – Tirth Jan 17 '13 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. – James M Jan 17 '13 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. – Tirth Jan 17 '13 at 10:20
  • Also i try to change extension of AppDelegate.m file to AppDelegate.mm but no success – Tirth Jan 17 '13 at 10:21
  • That header contains nothing that depends on `iostream`, so you should include it in the .mm file instead of the .h file. – molbdnilo Jan 17 '13 at 10:56
  • don't use double-underscore names. those are reserved to the standard library implementation. – Sebastian Mach Jan 17 '13 at 11:20
  • @phresnel, thanks, i will keep remember it. – Tirth Jan 17 '13 at 12:51
  • Possible duplicate of [iostream.h, fstream.h cannot be found](https://stackoverflow.com/questions/2225277/iostream-h-fstream-h-cannot-be-found) – rptwsthi Nov 16 '18 at 08:04

1 Answers1

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.

arthankamal
  • 6,341
  • 4
  • 36
  • 51