Objective c 从std::string转换为NSString
在这种情况下,如何将std::string转换为NSStringObjective c 从std::string转换为NSString,objective-c,objective-c++,Objective C,Objective C++,在这种情况下,如何将std::string转换为NSString void Piles::imagePlacer(Card card, int xCoord, int yCoord) { string cardType = card.toString(); UIImageView *cardImg = [[UIImageView alloc] initWithImage:cardType]; cardImg.frame = CGRect
void Piles::imagePlacer(Card card, int xCoord, int yCoord) {
string cardType = card.toString();
UIImageView *cardImg = [[UIImageView alloc]
initWithImage:cardType];
cardImg.frame = CGRectMake(xCoord, yCoord, 126, 190);
[self.view addSubview:cardImg];
}
我想使用一个字符串作为图像的名称(假设我有一个UIImages列表,其中的名称对应于存储在cardType中的所有可能的字符串)?只需浏览一个C字符串:
[nsstringwithutf8string:cardType.c_str()]
或者使用新语法:
@(cardType.c_str())
下面是一个示例:
string str_simple = "HELLO WORLD";
//string to NSString
NSString *stringinObjC = [NSString stringWithCString:str_simple.c_str()
encoding:[NSString defaultCStringEncoding]];
NSLog(stringinObjC);