I want to initialize a string with a single character. The following code doesn't work:
int main()
{
string s = 'c';
cout<<s;
return 0;
}
// Result:
error: conversion from ‘char’ to non-scalar type ‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’ requested
string s = 'c';
But the following does. Why is it so?
int main()
{
string s;
s = 'c';
cout<<s;
return 0;
}
// Output: c[Finished in 0.8s]