Can't convert to upper case (string)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • conan9
    New Member
    • Mar 2008
    • 2

    Can't convert to upper case (string)

    Hi folks,,

    I'm new here and having trouble to compile uppercase ....

    and here is my code:
    Code:
    #include <iostream>
    #include <string>
    #include <iomanip>
    #include <algorithm>
    
    using std::cout;
    using std::cin;
    using std::endl;
    using std::string;
    using std::getline;
    using std::fixed;
    using std::setprecision;
    using std::transform;
    using namespace std;
    
    
    
    int main()
    {
    	//declaring a variable
    	string state="";
    	
    	//getting the input
    	cout<<"Enter the State : "<<endl;
    	cin>>state;
    
    	
    	//states=toupper(states);
    	transform(state.begin(), state.end(), state.begin(), toupper);
    	
    	//determain the state that the user input
    	if (state=="HAWAII")
    	{
    		cout<<"The shipping charge for Hawaii is $30.00. "<<endl;
    	}//end if
    	else if (state=="OREGON")
    	{
    		cout<<"The shipping charge for Oregon is $30.00."<<endl;
    	}//end else if
    	else
    	{//end else
    		cout<<"Incorrect State..";
    	}
    	
    return 0;
    }
    and this is the error knowing that I have Mingw as a compiler:

    Code:
     ----jGRASP exec: g++ -g C:\Users\Conan9\Desktop\ChargeStates.cpp
    
    C:\Users\ayman\Desktop\ChargeStates.cpp: In function `int main()':
    ChargeStates.cpp:29: error: no matching function for call to `transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, <unknown type>)'
    ChargeStates.cpp:46:2: warning: no newline at end of file
    
     ----jGRASP wedge2: exit code for process is 1.
     ----jGRASP: operation complete.


    Please Help!!
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Code:
    int main()
    {
    	//declaring a variable
    	string state="";
    	
    	//getting the input
    	cout<<"Enter the State : "<<endl;
    	cin>>state;
    
    	
    	//states=toupper(states);
    	transform(state.begin(), state.end(), state.begin(), toupper);
    What is toupper in the last line? It's not a function - you don't pass it anything or save the return value. It's not a variable, you haven't declared it... The line above it looks more correct than the last line...

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Your code works fine using Visual Studio.NET 2005. Hawaii gets converted to HAWAII just as you wish.

      To Sicarie:

      toupper is the address of the toupper(). The transform algorithm will call toupper() using each element of the container, in this case a char.

      You are supposed to do this rather than code your own loop.

      Comment

      • conan9
        New Member
        • Mar 2008
        • 2

        #4
        Originally posted by weaknessforcats
        Your code works fine using Visual Studio.NET 2005. Hawaii gets converted to HAWAII just as you wish.

        To Sicarie:

        toupper is the address of the toupper(). The transform algorithm will call toupper() using each element of the container, in this case a char.

        You are supposed to do this rather than code your own loop.

        Thank you all,

        However why is it not working when using Jgrasp??

        Conan9

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          You might try including <functional>. That's supposed to be included by <algorithm> but one never knows.

          Comment

          • sicarie
            Recognized Expert Specialist
            • Nov 2006
            • 4677

            #6
            Originally posted by weaknessforcats
            To Sicarie:

            toupper is the address of the toupper(). The transform algorithm will call toupper() using each element of the container, in this case a char.

            You are supposed to do this rather than code your own loop.
            Wow, I've never seen that. Thanks for the clarification.

            Comment

            Working...