ข้อผิดพลาดต่อไปนี้ล้มเหลว 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;
}
ขออภัยสำหรับคำถามโง่ ๆ นี้ แต่ฉันค้นหารอบ ๆ google สิ่งที่ฉันเห็นคือ "char array to char ptr", "char ptr to char array" ฯลฯ