Hi theman,
I've been looking at your code. From what I can gather, you want the user to enter a series of
strings, where for each
string you want to determine and isolate the characters not belonging to those in the string literal
"\".!?,".
You then seem to want to invoke the overloaded function
tolower to take these parts of the
string and set all capital letters to lower case.
What I am not clear about is what you want to do with them then. You append
rad to
ord only then to overwrite
ord later on(!), which doesn't make much sense to me.
In any case, I think the problem with compilation is due to the
tolower function, since the
isupper function is supposed to take a
char rather than a
std::iterator_traits<string::iterator>::value_type.
I made some modifications to the
tolower function, and it seems to work:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
string tolower(const char* sma, size_t sz)
{
size_t i = 0;
char ret[sz];
while(sma[i])
{
ret[i] = tolower(sma[i]);
++i;
}
ret[i] = '\0';
return ret;
}
|
where the first argument is the input string converted to a
char[], and the second argument is a
size_t containing the size of that array. The function then returns the desired
string.
I am not sure what you want to do in
main() after
tolower is utilised. However, I changed your
main() function to append all parts of the user-inputted strings that don't include the characters in the string literal
"\".!?," after being converted to lower case:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
int main()
{
map<string, int> ord_lista; //not sure what this does
string ord, rad, temp;
string::size_type beg = 0, end = 0;
while(getline(cin,rad))
{
end = 0;
beg = rad.find_first_not_of("\".!?,", 0);
while (beg != string::npos)
{
end = rad.find_first_of("\".!?,", beg);
temp = rad.substr(beg, end - beg);
cout << temp << endl;
ord += tolower(temp.c_str(), temp.size());
beg = rad.find_first_not_of("\".!?,", end);
}
}
}
|
As indicated, I am not sure what you want to do with the
map<string, int>, ord_lista, but I guess you might now be in a better position to determine that.
I hope this helps, good luck!