Joh*_*ith 3 iphone xcode objective-c objective-c++
我刚刚将我的代码从Objective-C切换到Objective-C++.除了两条线外,一切都在游动.
NSString * text1=[[NSString stringWithFormat:@"%.2f",ymax] UTF8String];
Run Code Online (Sandbox Code Playgroud)
这条线抱怨说
error: cannot convert 'const char*' to 'NSString*' in initialization
Run Code Online (Sandbox Code Playgroud)
与第一个相关的第二个错误来自以下行:
CGContextShowTextAtPoint(context, 2, 8, text1, strlen(text1));
Run Code Online (Sandbox Code Playgroud)
它抱怨说
error: cannot convert 'NSString*' to 'const char*' for argument '1' to 'size_t strlen(const char*)'
Run Code Online (Sandbox Code Playgroud)
ObjC和ObjC++之间的区别是否有一些错过的东西?
你要:
const char * text1 = [[NSString stringWithFormat:@"%.2f", ymax] UTF8String];
Run Code Online (Sandbox Code Playgroud)
不:
NSString *text1 = [[NSString stringWithFormat:@"%.2f", ymax] UTF8String];
Run Code Online (Sandbox Code Playgroud)
(注意-UTF8String的返回值.)
| 归档时间: |
|
| 查看次数: |
1592 次 |
| 最近记录: |