| | |
uppercase and lowercase
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2009
Posts: 8
Reputation:
Solved Threads: 0
Hey...
I've written a program that changes a single character from uppercase to lowercase and viceversa but I want to change a whole word from uppercase to lowercase and viceversa
how do I do that?
I've written a program that changes a single character from uppercase to lowercase and viceversa but I want to change a whole word from uppercase to lowercase and viceversa
how do I do that?
C++ Syntax (Toggle Plain Text)
#include <cctype> #include <iostream> using namespace std; int main() { for (int i=1;i<=10;i++){ char ch; cout<<"Enter a character: "; cin>> ch; if ( isalpha ( ch ) ) { if ( isupper ( ch ) ) cout<<"The lower case equivalent is "<< static_cast<char> ( tolower ( ch ) ) <<endl; else cout<<"The upper case equivalent is "<< static_cast<char> ( toupper ( ch ) )<<endl; } else cout<<"The character is not a letter"<<endl; while ( cin.get ( ch ) && ch != '\n' ) ; } system("pause"); return 0; }
•
•
Join Date: Jan 2008
Posts: 3,840
Reputation:
Solved Threads: 503
0
#2 Nov 11th, 2009
Go through the word character by character and change each character to upper or lower case using toupper or tolower from cctype. There is no toupper or tolower function that takes a string as a parameter and converts the whole string.
I'm sure many people have written one, but it's not a standard function.
I'm sure many people have written one, but it's not a standard function.
0
#3 Nov 12th, 2009
Here's mine:
c++ Syntax (Toggle Plain Text)
#include <iostream> #include <algorithm> #include <string> #include <cctype> struct upper { int operator() ( int c ) { return toupper ( static_cast<unsigned char> ( c ) ); } }; struct lower{ int operator() ( int c ) { return tolower( static_cast<unsigned char> ( c ) ); } }; int main(){ std::string str = "Test StrinG"; std::transform(str.begin(),str.end(),str.begin(),upper()); std::cout << str; std::transform(str.begin(),str.end(),str.begin(),lower()); std::cout << str; return 0; }
•
•
Join Date: Nov 2009
Posts: 182
Reputation:
Solved Threads: 11
0
#4 Nov 12th, 2009
Which flavor of c++ are you using? I use VC++ for work and I use the MakeLower() function on strings.
Also, here's a dreamincode thread about a similar issue.
Also, here's a dreamincode thread about a similar issue.
•
•
Join Date: Jan 2008
Posts: 3,840
Reputation:
Solved Threads: 503
0
#5 Nov 12th, 2009
•
•
•
•
Which flavor of c++ are you using? I use VC++ for work and I use the MakeLower() function on strings.
http://www.cplusplus.com/reference/
I know of no function in this set of functions that will do the job. But you're right. Visual C++ will have a lot of things beyond that. You can also look at the Boost functions. They could be in there too.
Last edited by VernonDozier; Nov 12th, 2009 at 11:29 am.
![]() |
Similar Threads
- uppercase to lowercase url's (Search Engine Optimization)
- Finer points of Uppercase and Lowercase (C++)
- Validate String Can Be Both Uppercase or Lowercase (As in a Name) (C++)
- LC3 Uppercase and Lowercase (Assembly)
- Converting uppercase to lowercase help???? (Java)
- uppercase and lowercase HELP! (Java)
Other Threads in the C++ Forum
- Previous Thread: C++ Square Problem HELP
- Next Thread: Opening Web page and control elements of the web.
Views: 400 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






