Write a program that tests maxLoc(). You can read a data file into a list and call the function maxLoc to find the largest element.
HERE IS WHAT IS IN THE TEXT FILE(Name):
Josh
King
Louis
Tony
Angel
here is the code:
#include <iostream>
#include <fstream>
#include <list>
using namespace std;
// return an iterator pointing to the largest element in the list.
template <class T>
list<string>::iterator maxLoc(list<string>& aList)
{
list<string>::iterator iter; //declare a variable
list<string>::iterator max;
//point to the begin of a list
max = aList.begin();
iter = max;
iter++;
while(iter !=aList.end())
(
if( *max<*iter)
max=iter;
iter++;
return max;
)
}
int main()
{
ifstream read("Name.txt");
string Name;
list<string> l;
list<string>::iterator large, temp;
temp=l.bein();
while (read>>Name)
(
l.push_back(Name);
)
large= maxLoc(1)
cout<<"Contents of the lists are: ";
while(temp !=l.end())
(
cout<<*temp<< " ";
)
system("pause");
return 0;
}
here is the errors:
List.cpp: In function `std::_List_iterator<std::string> maxLoc(std::list<std::string, std::allocator<std::string> >&)':
List.cpp:20: error: expected primary-expression before "if"
List.cpp:20: error: expected `)' before "if"
List.cpp:24: error: expected primary-expression before ')' token
List.cpp:24: error: expected `;' before ')' token
List.cpp: In function `int main()':
List.cpp:33: error: 'class std::list<std::string, std::allocator<std::string> >' has no member named 'bein'
List.cpp:36: error: expected `)' before ';' token
List.cpp:37: error: expected primary-expression before ')' token
List.cpp:37: error: expected `;' before ')' token
List.cpp:45: error: expected `)' before ';' token
List.cpp:46: error: expected primary-expression before ')' token
List.cpp:46: error: expected `;' before ')' token
make.exe: *** [List.o] Error 1
Execution terminated