string convert(string name)
{
string code = name[0];
...
}
Run Code Online (Sandbox Code Playgroud)
我从这一行中得到“没有从 'value_type'(又名 'char')到 'string'(又名 'basic_string, allocator >')的可行转换”。
如果我将其更改为:
string convert(string name)
{
string code;
code = name[0];
...
}
Run Code Online (Sandbox Code Playgroud)
然后它起作用了。谁能解释为什么?
在C++中,我正在尝试打印C字符串的地址但是我的演员似乎有些问题.我从一本书中复制了代码,但它不能在我的mac上编译.
const char *const word = "hello";
cout << word << endl; // Prints "hello"
cout << static_cast< void * >(word) << endl; // Prints address of word
Run Code Online (Sandbox Code Playgroud)