-
compiler error
Ok I know this has to be a quick fix- which will make me feel awful but I can't get this progam to run because WriteList is not a member of list. Am I putting the wrong info in, am I putting it in the wrong place??? Am I forgetting to #include something???
Code:
#include<iostream>
#include<string>
#include<list>
using namespace std;
template<class T>
void WriteList(list<T> S){
list<T>::iterator iter;
for(iter=S.begin();iter!=S.end();iter++){
cout << *iter<< " " <<;
};
cout <<endl;
}
int main(){
list<string> S;
S.push_back("a");
S.push_back("b");
S.push_back("c");
S.push_back("d");
S.push_back("e");
S.push_back("f");
S.push_back("g");
S.push_back("h");
S.push_front("x");
S.push_front("y");
S.push_front("z");
S.WriteList();
S.pop_back();
S.pop_back();
S.pop_back();
S.WriteList();
return 0;
}
Thanks!!
-
I've never used list before but I can see from MSDN that it has no function member named WriteList. Where'd you get your information?
-
You had a few mistakes.
Code:
#include<iostream>
#include<string>
#include<list>
using namespace std;
template<class T>
void WriteList(list<T>& S)
{
list<T>::iterator iter;
for(iter=S.begin();iter!=S.end();iter++)
cout << *iter << " ";
cout << endl;
}
int main()
{
list<string> S;
S.push_back("a");
S.push_back("b");
S.push_back("c");
S.push_back("d");
S.push_back("e");
S.push_back("f");
S.push_back("g");
S.push_back("h");
S.push_front("x");
S.push_front("y");
S.push_front("z");
WriteList( S );
S.pop_back();
S.pop_back();
S.pop_back();
WriteList( S );
return 0;
}
-
Thanks for the help!! My professor gave me the code for WriteList.
Thanks again!!