Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting from std::string to NSString

How can I convert from std::string to NSString in this case?

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];
}

I want to use a string as the name of the image (assuming I have a list of UIImages somewhere with names that correspond to all possible strings stored in cardType)?

like image 788
user1824518 Avatar asked Jul 04 '26 08:07

user1824518


1 Answers

Just go through a C string:

[NSString stringWithUTF8String:cardType.c_str()]

or using the new syntax:

@(cardType.c_str())

like image 162
newacct Avatar answered Jul 06 '26 22:07

newacct



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!