473,243 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,243 software developers and data experts.

C++ toupper()

eboyjr14
I am very new to C++. I am just learning and wanted to make a simple program that capitalizes the input. What is wrong with this? I use Bloodshed Dev-C++. I get this error:

no matching function for call to `toupper(std::string&)'
candidates are: int toupper(int)

Expand|Select|Wrap|Line Numbers
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9.     while( true )
  10.            {
  11.            cout << "fire> ";
  12.            string cmd;
  13.            getline(cin, cmd);
  14.            string upp;
  15.            upp = toupper(cmd);
  16.            cout << upp << endl << endl;
  17.            }
  18.     return EXIT_SUCCESS;
  19. }
  20.  
Jun 21 '07 #1
7 21887
Meetee
931 Expert Mod 512MB
I am very new to C++. I am just learning and wanted to make a simple program that capitalizes the input. What is wrong with this? I use Bloodshed Dev-C++. I get this error:

no matching function for call to `toupper(std::string&)'
candidates are: int toupper(int)

Expand|Select|Wrap|Line Numbers
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9.     while( true )
  10.            {
  11.            cout << "fire> ";
  12.            string cmd;
  13.            getline(cin, cmd);
  14.            string upp;
  15.            upp = toupper(cmd);
  16.            cout << upp << endl << endl;
  17.            }
  18.     return EXIT_SUCCESS;
  19. }
  20.  

use char * instead of string
Jun 21 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
You don't need to revert to C and char*. You can still use your string. Each element of the string is a char.
Expand|Select|Wrap|Line Numbers
  1. string str("aBcDeF");
  2. int length = str.size();
  3. for (int i = 0; i < length; ++i)
  4. {
  5.     str[i] = toupper(str[i]);
  6. }
  7. cout << str << endl;
  8.  
You can even avoid writing the loop byb using the transform() algorithm:
Expand|Select|Wrap|Line Numbers
  1. string str("aBcDeF");
  2. transform(str.begin(), str.end(), str.begin(), toupper);
  3. cout << str << endl;
  4.  
Now you are down to three lines of code.
Jun 21 '07 #3
I am very new to C++. I am just learning and wanted to make a simple program that capitalizes the input. What is wrong with this? I use Bloodshed Dev-C++. I get this error:

no matching function for call to `toupper(std::string&)'
candidates are: int toupper(int)

Expand|Select|Wrap|Line Numbers
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9.     while( true )
  10.            {
  11.            cout << "fire> ";
  12.            string cmd;
  13.            getline(cin, cmd);
  14.            string upp;
  15.            upp = toupper(cmd);
  16.            cout << upp << endl << endl;
  17.            }
  18.     return EXIT_SUCCESS;
  19. }
  20.  
Be careful:
use #include <cstring> or #include <string.h> but be careful because <string> does not exist!!
Jun 23 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
Be careful:
use #include <cstring> or #include <string.h> but be careful because <string> does not exist!!
What does this mean?

string.h is the C string header.
cstring is the C++ version of the C header
string is the header for the C++ string class inthe C++ Standard Library

Why do you say <string> does not exist? It has to exist if the compiler is sold as C++ compiler.
Jun 24 '07 #5
You would do well to remove the arguments in the main () when starting to use Dev, using their template causes you to follow those argument parameters. I would get rid of the template return exit success also, simply build a template with your most often used headers, int main () and a return 0; I like to add a system ("pause"); also prior to the return statement otherwise a lot of programs I write I cannot get to display in the cmd screen.

A cstdlib does include # <string>, works for me anyway. When using the manipulator toupper I always include <iomanip>, don't know if you need the library or not but it seems easier to simply use it if your not sure. Anytime I am manipulating anything even setw(3) I use #include <iomanip>, give it a shot it may help you out. You also refer to your 'get' with 'cin' the common input operator which I believe you needed to call prior to, I'm just learning myself.
Whenever I use any of the following I include iomanip in my file headers.

C++ I/O Manipulators

boolalpha
dec
fixed
hex
internal
left
noboolalpha
noshowbase
noshowpoint
noshowpos
noskipws
nounitbuf
nouppercase
resetiosflags
right
scientific
setbase
setfill
setiosflags
setprecision
setw
showbase
showpoint
showpos
skipws
unitbuf
uppercase
ws

Good luck.
Aug 30 '07 #6
Banfa
9,065 Expert Mod 8TB
no matching function for call to `toupper(std::string&)'
candidates are: int toupper(int)
I thought I would just mention because, no-one else has, that the actual reason for this warning is that the only toupper() function that exists is in the C runtime library and has this prototype

int toupper( int ch );

you need to include ctype.h (C) or cctype (C++)

This function takes a character value (in C character constants have type int hence the function takes and returns int) and returns the uppercased version of that character.

You tried to pass a string to toupper, since that does not match this prototype your compiler looked for a function overload that did take a string, failed to find one and produced the error.
Aug 30 '07 #7
What does this mean?

string.h is the C string header.
cstring is the C++ version of the C header
string is the header for the C++ string class inthe C++ Standard Library

Why do you say <string> does not exist? It has to exist if the compiler is sold as C++ compiler.
May 2 '19 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Kerri | last post by:
Hi, I have a string 'hello world' I can UCase my string using String.ToUpper Is there anyway to just UCase the first letter ofe ach word? Thanks,
2
by: JasBascom | last post by:
if i have struct crecord{ char record_type; } if record_type = 'c'; how do I make record_type toupper?
7
by: Duane | last post by:
Aside from the pitfalls of using this function, according to the standard, what is the correct way to call it? #include <string> #include <locale> // seems to work with BCC5.6/STLPort...
18
by: didgerman | last post by:
Chaps, I need to properly format the case of a struct. Can I just hit it with tolower, and then 'while (string ==' ') pos++; string=toupper(string); to add in the higher case for the start of...
3
by: gelbeiche | last post by:
I have a question regarding the following small C program. #include <locale.h> int main() { char* loc = 0; char before,after; int i;
0
by: Shrinivas Reddy | last post by:
Hi, I am using the ToUpper() function in an FXCop rule which checks whether a boolean variable has "is" or "has" as the prefix. The ToUpper() function does not work. When I put the expression...
48
by: Frederick Gotham | last post by:
The "toupper" function takes an int as an argument. That's not too irrational given that a character literal is of type "int" in C. (Although why it isn't of type "char" escapes me... ) The...
4
by: sandy | last post by:
I am trying to upper case a string, so I have this method: string FileSystem::toupper(string S) { for (int i=0; i<S.length(); ++i) { S=toupper(S); } return S;
13
by: JanWhitney | last post by:
I am learning C++, so please be kind. Is there anywhere that I can view the source code for the toUpper function? Thanks.
16
by: gaga | last post by:
my function should accept a pointer to a string as its argument. and it should convert each charater to an uppercase letter. I know what i need to do, its just my syntax is all out of whack. ...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.