2013-11-27 5 views
2

코드를 NSString으로 변환하려면 어떻게해야합니까?C++ 문자열을 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()]; 

그러나 cypNSString을 널 ..

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 *s1 = @(YOURCSTRING.c_str()); 
+0

있는 NSString stringWithCString : 인코딩 : 다른 인코딩으로 t은 –

+0

거의 확실하게 문자열이 UTF8로 인코딩되지 않았습니다. –

+0

또는 자세히 살펴보면 해당 문자열이 나타나지만 실제로는 암호 텍스트입니다.이 경우 실제 " 문자열 "- 문자 데이터가 아닙니다. –

답변

2

이 나를 위해 작동하는지보십시오 "암호문"에서는 NSString을 만들 수 있습니다. 또한 ciphertext.c_str() 반환 값을 확인하십시오.
+0

이 답변을 보려면 C 문자열이 UTF-8을 사용하도록기도해야합니다. 만약 그렇다면, 이것이 최선의 대답입니다. – JeremyP