Can someone tell me why I am getting an: "Illegal use of this type of expression: std::string" on the line with the for loop? As far as I can tell everything should be set up correctly. I'm trying to walk through the strings in the vector and check each string member for capitalization (although I'm really only interested in the first one so that the sorting algorithm doesn't separate uppercase words vs. lowercase words...)
/* BiasedSort: accepts vector<string> by REFERENCE and sorts the vector lexographically, except that if the vector
* contains "Me First", that string is always at the front.
*/
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std;
// getting error on the "for" line.
void ConvertToLower (vector<string> &vector)
{
for (vector<string>::iterator iter = vector.begin();
iter != vector.end(); ++iter) {
string iterString = *iter;
transform(iterString.begin(), iterString.end(), iterString.begin(), ::tolower);
}
}
void BiasedSort (vector<string> &vector)
{
ConvertToLower(vector);
sort(vector.begin(), vector.end());
}
int main ()
{
vector<string> myVector;
myVector.push_back("this");
myVector.push_back("string");
myVector.push_back("and");
myVector.push_back("vector");
myVector.push_back("are for");
myVector.push_back("testing");
myVector.push_back("purposes");
copy(myVector.begin(), myVector.end(), ostream_iterator<string>(cout, " "));
cout << endl;
BiasedSort(myVector);
copy(myVector.begin(), myVector.end(), ostream_iterator<string>(cout, " "));
cout << endl;
system("pause");
return 0;
}
abusing namespace std;Just say no.using namespace std. Without that you would have had to prefix the libary items withstd::, and everything would have worked fine.