Need help : No Viable Conversion

Revision en1, by immadmohit, 2021-08-09 11:16:21

Hello, I actually searched this issue on google and got one answer on stack overflow but was not able to understand it well, Can someone explain to me why am I getting this error.

string convert(string name)
{
  string code = name[0];
  ...
}

I am getting "no viable conversion from 'value_type' (as of 'char') to 'string' (as of 'basic_string, allocator >')" from this line.

But if I will change this code to this:

string convert(string name)
{
  string code;
  code = name[0];
  ...
}

Then it will work fine. Thanks in advance.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English immadmohit 2021-08-09 11:16:21 613 Initial revision (published)