簡體   English   中英

將UITextField(field.text)NSString *轉換為char *?

[英]Converting UITextField ( field.text) NSString * to char *?

我想將NSString* str轉換為char* ch ,以便在此函數中將其用作參數: str是從UITextField's文本中獲取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 *')

代替它

ch = [str UTF8String];

const char *ch = [str UTF8String];

或嘗試:

ch = (char *)[str UTF8String];

您為什么不嘗試顯而易見的解決方案? 正確聲明指針:

const char *ch = [str UTF8String];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM