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 .c
extension) with a C compiler.
This won't work, since you're using the C++ STL (and namespace std
).
Compile using g++
instead:
g++ queuetest.cpp -o queuetest
See the docs for compiling C++. Consider changing your extension to .cpp
as well.
You'll also want to #include <iostream>
for cout
.
精彩评论