Reputation: 33
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: https://i.sstatic.net/1TMm6.png
Upvotes: 2
Views: 492
Reputation: 33
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
Upvotes: 0
Reputation: 3653
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
Upvotes: 2