2016-11-23 104 views
0

我寫這樣字符串爲char *在Xcode C++

class A{ 
// ... 
public: 
insert(int key, char* contents){ ... } 
} 

的代碼,並希望使用

A.insert(1, "hellow world"); 

,但不允許從字符串文字轉換爲char *

如何可以使用這樣的方式?

+0

的可能的複製[這是在C和C++字符串文字的類型?](http://stackoverflow.com/questions/2245664/what-is-the-type-of-string-literals-在-C-和-C) – Danh

+0

僅使用C++字符串文字 – jjj111144444

回答

0

文字串是一個const char*

class A{ 
    // ... 
    public: 
    insert(int key, const char* contents){ ... } 
} 

// ... 
A.insert(1, "hello world");