I'm working on a project for fun and was trying to figure out how do I capitalize whatever the user inputted in all caps? For example I want it to print
NAME1 NAME2 NAME3 etc. I'm using an old homework layout that we had to do with integers and just switched it to string. But my question remains, how do I capitalize every letter that the user inputted? Here's what I have so far. I also found a new method called toupper but I don't completely get it.
I'm back and realized I copied my past homework code lol. This is my code to my side project however it isn't working when I try it. I get "error: cannot convert ‘const string {aka const std::basic_string}’ to ‘int’ for argument ‘1’ to ‘int toupper(int)’" at line 85. I get that I can't pass a string where an int is expected but I've never tried this before so any suggestions? Sorry for the mix up
So with std::toupper I get, "error: no matching function for call to ‘toupper(const string&)’"
and with ::toupper I get, "error: cannot convert ‘const string {aka const std::basic_string}’ to ‘int’ for argument ‘1’ to ‘int toupper(int)’"
and with just toupper I get, "error: no matching function for call to ‘toupper(const string&)’"
seeplus already showed you, you need some sort of helper function to convert the whole string to uppercase. The built-in library toupper (and tolower, isdigit, isalpha, etc.) expects a single character as its argument, so you need to loop through every character.
<I wrote the following before having seen seeplus's reply, so it's entirely redundant>
You could write a helper function to convert every character in a string to uppercase.