我試圖在Visual Studio 2010中使用這些庫使用peek
功能:C++無法使用PEEK()函數棧
#include "stdafx.h"
#include <string>
#include <string.h>
#include <fstream>
#include <iostream>
#include <string.h>
#include <vector>
#include <stack>
但是,我不能使用peek
函數棧:
void dfs(){
stack<Node> s;
s.push(nodeArr[root]);
nodeArr[root].setVisited();
nodeArr[root].print();
while(!s.empty()){
//peek yok?!
Node n=s.peek();
if(!n.below->isVisited()){
n.below->setVisited();
n.below->print();
s.push(*n.below);
}
else{
s.pop();
}
}
}
我得到的錯誤:
Error 1 error C2039: 'peek' : is not a member of 'std::stack<_Ty>'
我在做什麼錯?
'stack'參考:http://en.cppreference.com/w/cpp/container/stack – hmjd 2012-03-30 21:19:06