将c++字符串转换为NSString
Convert c++ string to NSString
如何将下面的代码转换为NSString
?
std::cout << "Cipher Text (" << ciphertext.size() << " bytes)" << std::endl;
for( int i = 0; i < ciphertext.size(); i++ ) {
std::cout << "0x" << std::hex << (0xFF & static_cast<byte>(ciphertext[i])) << " ";
}
std::cout << std::endl << std::endl;
我试过了:
NSString *cyp = [NSString stringWithUTF8String:ciphertext.c_str()];
但是cyp
NSString
为空。。
NSString *cyp = @(ciphertext.c_str());
NSLog(@"cypher %@",cyp);
NSLog(@"cypher %s",ciphertext.c_str());
打印输出:
Pas[8044:70b] playntext Now is the time for all good men to come to the aide...
2013-11-27 14:38:01.421 Pas[8044:70b] cypher (null)
2013-11-27 14:38:01.422 Pas[8044:70b] cypher ¯≥Íä≥z=(fúóß≥¢P%Ä’“2ŒË
W3ÔpˇHÈËò©¬^ß∞@C°¸#±°Î≤ˆóbp°Å nxÄê
2013-11-27 14:38:01.423 Pas[8044:70b] decrypted Now is the time for all good men to come to the aide...
那么,为什么我可以像字符串一样打印出来,但不能从"密文"创建NSString
试试这对我有用:
NSString *s1 = @(YOURCSTRING.c_str());
相关文章:
- 防止主数据类型C++的隐式转换
- 模板参数替换失败,并且未完成隐式转换
- 努力将整数转换为链表。不知道我在这里做错了什么
- HEX值到wchar_t字符(UTF-8)的转换
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将 Qvector<uint8_t> 转换为 QString
- 如何在cuSparse中使用cusparseXcoo2csr从coo转换为csc
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中使用nlohmann从类到json的转换
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 将Integer转换为4字节的unsined字符矢量(按大端字节顺序)
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- 如何将 UTF8 std::string 转换为 NSString
- 将c++字符串转换为NSString
- 将 NSString 转换为 C 字符串时出错
- 如何将多字节UTF-8 std::string转换为NSString
- 在没有Obj-c代码的情况下,我如何在c++中将NSString转换为CString
- Objective-C++ 将 std::string 转换为 NSString
- 当尝试将const char *转换为NSString时为空字符串