toupper problem

//i want to convert a string in to uppercase
// but it gives me an error:
//could not find a match for 'toupper(charT)(string)' in function main()
//could somebody explain what the error meant and give me a solution tnx..

#include<string.h>
#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;


void main()
{
int i, iNumberInput;
clrscr();
cout <<"Enter number of inputs: \n";
cin >> iNumberInput;
int* iNumber = new(nothrow) int[iNumberInput];
string* sName = new(nothrow) string[iNumberInput];
i=0;
clrscr();
for(int x=0;x<iNumberInput;x++,i++)
{
cout << "please input the following data!" << endl << endl;
cout << "Enter a number input ."<< (i+1) << endl;
cin >> iNumber[x];
cout << "Enter a name input ."<< (i+1) << endl;
cin >> sName[x];
clrscr();
}
cout << "you are done with the inputs!" << endl << endl;
cout << "The following are: " << endl << endl;
for(int x=0;x<iNumberInput;x++)
{
cout << sName[x] << " is "<< iNumber[x] << " years old." << endl;
}
cout << endl;
for(int x= 0;x<iNumberInput;x++){
for(int d = iNumberInput;d>x;d--){
if(iNumber[x]>iNumber[d]){
cout << sName[x] << " is older that " << sName[d] <<"." << endl;
}}}
cout << endl;
for(int x= 0;x<iNumberInput;x++){
for(int d = iNumberInput;d>x;d--){
if(iNumber[x]>iNumber[d]){
cout << sName[d] << " is " << (iNumber[x]-iNumber[d]) << " years younger than " << sName[x] <<"." << endl;
}}}
cout << endl;
for(int x=0;x<iNumberInput;x++)
{
cout<< "there are " << sName[x].length() <<" characters in: " << sName[x]<< endl;
}
cout << endl;
int d=0;
string rave = sName[0];
for(int x=0;x<iNumberInput-1;x++,d++){
cout << "uppercase of " << sName[d] <<" is: "<< toupper(sName[d+1]) << endl;
sName[d] = sName[d+1];
if(x==iNumberInput-2)
{
cout << "uppercase of " << sName[d] <<" is: "<< toupper(rave) << endl; // <=
}} // this part
sName[d] = rave;
cout << endl;
d=iNumberInput-1;
string rave2 = sName[d];
for(int x=0;x<iNumberInput-1;x++,d--){
cout << "lower of " << sName[d] <<" is: "<< tolower(sName[d-1]) << endl; // <=
sName[d]= sName[d-1]; // this part
if(d==1)
{
cout << "lowers of " << sName[d] <<" is: "<< tolower(rave2) << endl;// <=
} // this part
}
delete [] sName;
delete [] iNumber;
}
std::transform(string.begin(),string.end(),string.begin(),toupper);
Don't forget to include <cctype> and <algorithm>.
does it work on tc++ compiler? because i use a different compiler here at home
How is he meant to know? Do you expect him to go downloading some compiler he's possibly never heard of?
If "tc++" is a standards-compliant compiler, it will work. What compiler do you use "at home"?
Yes, it should work on any compiler released since 1998.
Because of the way toupper() is handled in various compilers, you also need to use <functional> and cast it to the proper type.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <algorithm>
#include <cctype>
#include <functional>
#include <string>

std::string uppercase( const std::string& s )
  {
  std::string result( s.length(), '\0' );
  std::transform(
    s.begin(),
    s.end(),
    result.begin(),
    std::ptr_fun <int, int> ( std::toupper )
    );
  return result;
  }

Hope this helps.
You mean there are compilers where toupper() isn't int toupper(int)?
GCC. toupper is overloaded to handle all the fancy C++ stuff.
I think he means the actual code... but then that doesn't explain why you need to typecast anything...
helios and duoas when i put your codes it gives me and error

my code gives me a error: could not find a match for 'toupper(charT)(string)' in function main()

helios gives an error: colud not find a match for trasform(InputIterator,OutputIterato,UnaryOperation)(char *,char *,char *,charT (*)(charT,const locale &))' function main()

duoas gives me a error: cannot generate template specialization for toupper(int), in function uppercase(const string)

colud not find a match for ptr_fun(Arg1,Arg2,Result)(charT (*)(charT,const locale &))' function uppercase (const string &)

colud not find a match for trasform(InputIterator,OutputIterato,BinaryOperation)(const char *,const char *,char *,undefined )' in function uppercase(const string &)

could not find a match for 'toupper(charT)(string)' in function main()

// im using the cmd as may complire so the txt error here is not copy paste

// maybe i forgot some thing or im missing some thing in may codes?
helios gives an error: colud not find a match for trasform(InputIterator,OutputIterato,UnaryOperation)(char *,char *,char *,charT (*)(charT,const locale &))' function main()
Did you include <algorithm> like I told you to?
yup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
std::string UCASE(std::string s)
{
  if(s.empty())
    return s;
  else
  {
    for(int i = 0; i < s.size(); i++)
    {
      if(s[i] >= 'a' && s[i] <= 'z')
        s[i] = (s[i] - ('a' - 'A'));
    }
  }
  return s;
}


This is what I use.
yup
Your compiler sucks.
tnx garob
Topic archived. No new replies allowed.