2013-04-21 70 views
1

我正在用C++編寫服務器程序,我在接受const char的方法。我有這個代碼,但它不會編譯說const char變量的問題

27 26 C:\Users\Owner\Desktop\main.cpp [Error] expected primary-expression before ',' token 

有人可以請解釋發生在我身上的事情。

std::string str = "Hello"; 
const char * c = str.c_str(); 
iResult = getaddrinfo(c*, 23, &hints, &result); 

回答

2

你有getaddrinfo(c*, ...,你應該刪除多餘*,第二個參數應該是作爲一個字符串的端口號:

getaddrinfo(c, "23", &hints, &result); 
+0

我試過,但後來我的編譯器抱怨,說27 46 C:\ Users \ Owner \ Desktop \ main.cpp [錯誤]從'int'無效轉換爲'const char *'[-fpermissive] – 2013-04-21 12:43:20

+0

@JoshSobel:請參閱我編輯的答案。 – RichieHindle 2013-04-21 12:43:48

+0

哦,謝謝虐待當我無法知道端口號是一個字符串時接受它 – 2013-04-21 12:44:27