Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

deque.at No Maching Function

I am trying to deque (a string element) from a deque data structure. But I am getting and error:

error: no matching function for call to ‘std::__cxx11::basic_string::basic_string(__gnu_cxx::__alloc_traitsstd::allocator<std::array<std::__cxx11::basic_string<char, 1> >, std::arraystd::__cxx11::basic_string<char, 1> >::value_type&)’
26 | string record = (string)records.at(0);

deque<array<string, 1>>     records;
string data("hello this is 1st record");
array<string, 1>        buffer{data};
records.push_back(buffer);

string record = (string)records.at(0); //error is reported at this line
printf("%s\n", record.c_str());

Can someone please give me a hint what I am doing wrongly.
As background, I have to cache the last 100 text messages, so I am using deque for this purpose.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It is not quite clear why you are using array as elements. The value returned from at is not a string but an array.

deque<array<string, 1>>     records;
string data("hello this is 1st record");
array<string, 1>        buffer{data};
records.push_back(buffer);

string record = records.at(0)[0];
                        ^^ get first element in deque
                              ^^ get first element in array

Do not use c-style casts ((string)...). They are almost always wrong (and when they are not, they should be replaced with a safer C++ cast). If you do not use the array (why? when it only holds a single element?) the code is

deque<string>     records;
string data("hello this is 1st record");
records.push_back(data);

string record = records.at(0);
                        ^^ get first element in deque
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading