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) -
#include <cstdlib>
-
#include <iostream>
-
#include <string>
-
-
using namespace std;
-
-
int main(int argc, char *argv[])
-
{
-
while( true )
-
{
-
cout << "fire> ";
-
string cmd;
-
getline(cin, cmd);
-
string upp;
-
upp = toupper(cmd);
-
cout << upp << endl << endl;
-
}
-
return EXIT_SUCCESS;
-
}
-
7 21995
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) -
#include <cstdlib>
-
#include <iostream>
-
#include <string>
-
-
using namespace std;
-
-
int main(int argc, char *argv[])
-
{
-
while( true )
-
{
-
cout << "fire> ";
-
string cmd;
-
getline(cin, cmd);
-
string upp;
-
upp = toupper(cmd);
-
cout << upp << endl << endl;
-
}
-
return EXIT_SUCCESS;
-
}
-
use char * instead of string
You don't need to revert to C and char*. You can still use your string. Each element of the string is a char. -
string str("aBcDeF");
-
int length = str.size();
-
for (int i = 0; i < length; ++i)
-
{
-
str[i] = toupper(str[i]);
-
}
-
cout << str << endl;
-
You can even avoid writing the loop byb using the transform() algorithm: -
string str("aBcDeF");
-
transform(str.begin(), str.end(), str.begin(), toupper);
-
cout << str << endl;
-
Now you are down to three lines of code.
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) -
#include <cstdlib>
-
#include <iostream>
-
#include <string>
-
-
using namespace std;
-
-
int main(int argc, char *argv[])
-
{
-
while( true )
-
{
-
cout << "fire> ";
-
string cmd;
-
getline(cin, cmd);
-
string upp;
-
upp = toupper(cmd);
-
cout << upp << endl << endl;
-
}
-
return EXIT_SUCCESS;
-
}
-
Be careful:
use #include <cstring> or #include <string.h> but be careful because <string> does not exist!!
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.
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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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,
|
by: JasBascom |
last post by:
if i have
struct crecord{
char record_type;
}
if record_type = 'c';
how do I make record_type toupper?
|
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...
|
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...
|
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;
|
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...
|
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...
|
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;
|
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.
|
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.
...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |