Earlier I converted character strings to all uppercase letters. Now i'm trying to do string variable to upper case. May I know what is wrong with my code? I'm not getting an output at all.
Sounds straightforward. Index out of range. You're using index 0-name.length, but name[name.length] is one element past the end of your string. Remember that arrays are 0-based.
Booradely I'm still not clear on this, but I'm assuming I'm suppose to change the range for that expression or make index=1.also, I thought name.length returns the total number of characters in the string.
I would use an iterator, but since you're a beginner: use the .size() member function of string. size will return the actual size (the number of characters in the string, aka: 0 being nothing) and you can use that.
(string.size() - 1) would be the last element in the string. If you want to loop through it, just use a for loop from 0, and while x < your_string.size().
for(unsignedint x = 0; x < your_string.size(); x++). Make an effort to understand this, or you will pay for it: you will be using these basics a lot as you progress.
Also, chars are implicitly converted to unsigned integers. You do not need to typecast toupper().
Also, you can use cout on toupper... it will display the return value.
cout<< toupper(your_string[x]);
******************************
Important: Your for-loop is bad: you can not use that. Study for loops in more detail. Hint: you should use a nested for-loop for this, or write another function that will display a string in all caps.
@IWishIKnew
Boost solution is the simplest to use, I find it most suitable for a simple task. (although it would indeed not answer OP's question "what's wrong with my code")
To do it right, first install ICU. Then install (compile) boost locale, making sure that it hooks ICU (it should by default, IIRC, but on Windows at least you might have to make sure that it does).
Once done, life gets significantly easier. You still have to be careful with multi-byte characters, of course.
For example, in the example in the FAQ, if you started with "GrüSSEN", then to_lower() would have returned "grüssen", instead of the correct (in this particular case) "grüßen".