immadmohit's blog

By immadmohit, history, 3 years ago, In English

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.

  • Vote: I like it
  • +11
  • Vote: I do not like it

| Write comment?