首页 > 代码库 > char * string nsstring 之间的相互转换

char * string nsstring 之间的相互转换

std::string转NSString

std::string _string("hello");

NSString *str= [NSString stringWithCString:_string.c_str() encoding:[NSString defaultCStringEncoding]];


NSString转std::string
NSString  * nsfaceName=@"HELLO";
const char  *  lpfaceName = [nsfaceName UTF8String];
std::string   strFaceName=  [nsfaceName UTF8String];
  1. //NSString转换char  
  2.   NSString * str1= @"Test";  
  3.   const char * c1 =[str1 UTF8String];  
  4.   //char转换NSString  
  5.   const char * c2 ="test";  
  6.   NSString *str2 = [NSString stringWithUTF8String:c2];