#include <openssl/evp.h>
#include <openssl/md5.h>
#include <string>
#include <stdio.h>
static std::string encode_pass(std::string pass)
{
std::string tmpStream;
//TODO:
return tmpStream;
}
如何调用这个cpp的函数得到结果呢?
我是这么做的。
新建一个oc的类,h文件:
#import <Foundation/Foundation.h>
@interface OCEncode : NSObject
+(NSString *)encodeString:(NSString *)str;
@end
然后m文件:
#import ...
static std::string encode_pass(std::string pass)
{
std::string tmpStream;
//TODO:
return tmpStream;
}
@implementation OCEncode
/**&nbs

本文介绍了如何在Objective-C中调用C++函数,以实现字符串的MD5编码。通过创建一个OC类,声明并实现C++函数,将Objective-C的NSString转换为C++的std::string,然后调用encode_pass函数进行处理,最后将结果转换回NSString返回。关键步骤包括导入所需的openssl库,进行类型转换,并确保正确引用C++代码。
最低0.47元/天 解锁文章
1438

被折叠的 条评论
为什么被折叠?



