简体   繁体   中英

C++ Class in IOS App, Xcode 5

I have an IOS app that is a single view application. It has a standard C++ class that I made in it, however, it is not accepting the cpp class. Here is a simplified version of the .h file(without those lines #s):

1 #ifndef __Calculator__Numbers__
2 #define __Calculator__Numbers__
3 #include <iostream>
4 class NumDigits
5 {
6 };
7 #endif 

I get the error: 'iostream' file not found

It appears as if the project doesn't have the C++ libraries? If this is it, how would I add them? If not, what should I do to fix this error? It looks like the cpp libraries are not included in my project: http://i.imgur.com/ZkJHb7j.png

Implementation files have the extension .m in Obj-C . To use a C++ file in your Xcode project with Objective-C you must use .mm extension and you can include C++ header in the .mm file. You mustn't include the header in .m file, but if you want to include your C++ header in .h , you will need a macro like:

#ifdef _CP
#include <iostream>
#endif

To solve this, I just took out all the macros, #include s, and class declarations:

#ifndef __Calculator__Numbers__
#define __Calculator__Numbers__
#include <iostream>
class NumDigits
{
};
#endif 

and left only the function declarations: void myFunction(int myVariable) ; Then in the .cpp:

#include <iostream> //and other #includes
void myFunction(int myVariable) {
//stuff
}

This worked because the functions were still called and values were passed to and from them. The return values were the values that should've been spit out. when in the .mm if the .cpp was #included , the iostream file couldn't be found so 3include the .h ,and in the .cpp , #include the .h

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM