【问题标题】:String to char* in Xcode c++Xcode c ++中的字符串到char *
【发布时间】:2016-11-23 04:35:56
【问题描述】:

我这样写代码

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

想用

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

但不允许从字符串文字转换为 char*

怎么可以这样使用?

【问题讨论】:

标签: c++ xcode string char


【解决方案1】:

字符串文字是const char*

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

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

【讨论】:

    猜你喜欢
    • 2012-02-20
    • 2013-10-30
    • 2012-08-16
    • 2018-09-02
    • 2017-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多