Question

I am trying to implement this answer to pass strings through boost::lockfree::queues.

It looks like it does work, but when I try to cout the pointer after popping it off the queue, it only reads out a memory address.

I have looked everywhere for a solution, but I strangely can't find one.

How can I get the contents of ptr below?

boost::lockfree::queue<std::string*> queue(some_size);
// push on via new
queue.push(new std::string("blah"));
// pop and delete
std::string* ptr;
if(queue.pop(ptr))
{
   std::cout << ptr << std::endl;
   delete ptr;
}

Result:

0x7f41fc000950
Was it helpful?

Solution

To get at contents of the string, just dereference the pointer, duh. ;-)

std::cout << *ptr << std::endl;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top