NSString 与C++ string字符串的互转 文件路径

Posted on 2012-03-13 23:36  无忧consume  阅读(276)  评论(0编辑  收藏  举报

1.  string 转换为 NSString  

     std::string str("hello");

     NSString *str=[NSString stringWithString:str.c_str()];

     NSString *istr=[NSString stringWithString:@"zsh"];

 

     str=[istr cStringUsingEncoding:NSUTF8StringEncoding];
     NSString *path=[[NSBundle mainBundle]pathForResource:@"nokia" ofType:@"mp3"];

  

     char *tempPath=(char*)malloc(sizeof(path)+1);

    
     NSString *soundPath=[[NSBundle mainBundle] pathForResource:@mp3"]; 
    
    NSString* dirStr = [NSString stringWithFormat:@"%s",path];
    NSString* filepath = [[NSBundle mainBundle] pathForResource:dirStr ofType:nil];

    NSLog(filepath);

2.  //NSString 转换为C 字符串

    const char* destDir = [filepath UTF8String];

   //  NSURL *soundUrl=[[NSURL alloc] initFileURLWithPath:s]; 

Copyright © 2024 无忧consume
Powered by .NET 9.0 on Kubernetes