我想在我可以寫這樣的方式來寫一個客觀-C++程序:目的-C++轉換的std :: string到的NSString
class foo
{
public:
foo()
{
bar = "Hello world";
}
std::string bar;
};
然後(下面在同一.mm文件)我可以創建類的實例,然後像做:
@interface ViewController()
@property (weak, nonatomic) IBOutlet UILabel *myLabel;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
foo* thisWontWork = new foo();
self.myLabel.text = foo.bar; //this doesn't work obviously
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
這將有效地改變標籤的文本「myLabel」在「Hello world」
self.myLabel.text = thisWontWork->吧? –
哦,是的,這是一個std :: string :) ..'self.myLabel.text = @(thisWontWork-> bar.c_str())' –
你想複製字符串中的數據,還是你想要在沒有獲得所有權的情況下呈現C++字符串中的數據的NSString? –