using namespace std;
int main() {
vector<string> vec;
vec.push_back("SEE"); vec.push_back("BE"); vec.push_back("Can");
//sort(vec.begin(), vec.end());
for (unsigned int i = 0; i < vec.size(); i++)
{
vec[i]=tolower(vec[i]);
cout << vec[i] << " ";
}
return 0;
}
At this time I would like to know how would you go about doing this? Any help will be greatly appreciated!!
#include <algorithm>
#include <cctype>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
usingnamespace std;
constchar* _strings[] =
{
"SEE",
"BE",
"Can"
};
int main()
{
vector <string> vec( _strings, _strings +3 );
// for each string in the vector
for (unsigned n = 0; n < vec.size(); n++)
{
// convert the string to lowercase
transform(
vec[ n ].begin(),
vec[ n ].end(),
vec[ n ].begin(),
ptr_fun <int,int> ( &tolower )
);
// show the user the result
cout << vec[ n ] << endl;
}
return 0;
}
Yes, the problem is that the tolower() function is used to convert one character to lowercase. Another solution is that you write the function to entire strings:
1 2 3 4 5 6 7 8
string toLowerCase(string s)
{
string r = s;
for (int i = 0; i < r.size(); i++)
if (r[i] >= 'A' && r[i] <= 'Z')
r[i] = tolower(r[i]);
return r;
}
Now you can use your code, just change tolower to toLowerCase:
@HarryGabriel91: CBaseConfigLoader is one of my classes in a project, As I said it's a copy + paste of mine. So you don't need it. But I'd expect people to be able to pick up on that.