-2

I am practicing on LeetCode.

I have the following CPP code:

string s="abcd"; 
queue<string> q; 
string temp; 
temp=s[2]; 
queue.push(temp);

Error:

Line 5: conversion from '__gnu_cxx::__alloc_traits >::value_type {aka char}' to non-scalar type 'std::__cxx11::string {aka std::__cxx11::basic_string}' requested

I am wondering why this happen? I can't really change thte structure of this because temp will be growing over time (eg., temp='a'+'b'+'c'; queue.push(temp));

randy
  • 155
  • 3
  • 9

1 Answers1

-1

Read your code again ,

I am sure that you wanted to write :

queue.push(temp);

like this :

q.push(temp);
hroussille
  • 419
  • 3
  • 12