我想将NSString* str
转换为char* ch
,以便将其用作此函数中的参数:
str
来自UITextField's
文字。
void CUserSession::Login (char *pUsername, char *pPassword)
请帮忙。
使用
ch = [str UTF8String];
//我收到了错误。
Cannot initialize a parameter of type 'char *' with an rvalue of type 'const char *'
然后使用
ch = (const uint8_t *)[str UTF8String];
//我收到错误。
Cannot initialize a parameter of type 'char *' with an rvalue of type 'const uint8_t *' (aka 'const unsigned char *')
答案 0 :(得分:3)
替换它
ch = [str UTF8String];
与
const char *ch = [str UTF8String];
或尝试:
ch = (char *)[str UTF8String];
答案 1 :(得分:1)
为什么不尝试明显的解决方案?正确声明指针:
const char *ch = [str UTF8String];