I'm trying to print the first item (top item) of a Deque
in C++ with the following piece of code:
#include <queue>
#include <deque>
#include <string>
using namespace std;
int main(int argc, char *argv[]){
deque<string> commandHistory;
for (int i = 0; i < 2; i++) {
commandHistory.push_back("asdf");
}
printf(commandHistory.at(1));
return 0;
}
However, I get an error in the printf statement:
error: cannot convert ‘__gnu_cxx::__alloc_traitsstd::allocator<std::__cxx11::basic_string<char
, std::__cxx11::basic_string >::value_type’ {aka ‘std::__cxx11::basic_string’} to ‘const char*’
However, I cannot cast commandHistory.at(1)
to a const char*
like so:
printf((const char*) commandHistory.at(1));