以下代码出错并提示:prog.cpp:5:13: error: invalid conversion from ‘char’ to ‘const char*’
int main()
{
char d = 'd';
std::string y("Hello worl");
y.append(d); // Line 5 - this fails
std::cout << y;
return 0;
}
我也尝试了以下代码,虽然编译通过,但在运行时表现不稳定:
int main()
{
char d[1] = { 'd' };
std::string y("Hello worl");
y.append(d);
std::cout << y;
return 0;
}
非常抱歉问这个愚蠢的问题,但我已经在谷歌上搜索过了,只看到了"char数组转char指针"、"char指针转char数组"等内容。