I have a small program that uses “trying to use” #include <queue>. I use Ubuntu OS but it says:
fatal error: queue: No such file or directory
Any ideas why, or what I need to do to make it work?
#include <queue>
using namespace std;
int main()
{
queue<int> Q;
Q.push( 1 );
Q.push( 2 );
Q.push( 3 );
cout << Q.front();
Q.pop();
cout << Q.front();
Q.pop();
cout << Q.front();
Q.pop();
return 0;
}
You are compiling your C++ program (which you saved with a
.cextension) with a C compiler.This won’t work, since you’re using the C++ STL (and namespace
std).Compile using
g++instead:See the docs for compiling C++. Consider changing your extension to
.cppas well.You’ll also want to
#include <iostream>forcout.