[RESOLVED] about Standard Template Library(uppercase and lowcase)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: [RESOLVED] about Standard Template Library(uppercase and lowcase)

  1. #1
    Join Date
    Apr 2009
    Posts
    636

    [RESOLVED] about Standard Template Library(uppercase and lowcase)

    so the Standard Template Library isn't portable\ANSI?
    i'm studing C++ using the Teach Your Self C++ in 1 Hour a Day. but seems these code isn't correct for GNU compiler:
    Code:
    #include <string>
    #include <iostream>
    #include <algorithm>
    
    
    int main ()
    {
        using namespace std;
    
    
        cout << "Please enter a string for case-convertion:" << endl;
        cout << "> ";
    
    
        string strInput;
        getline (cin, strInput);
        cout << endl;
    
    
        transform(strInput.begin(),strInput.end(),strInput.begin(),toupper);
        cout << "The string converted to upper case is: " << endl;
        cout << strInput << endl << endl;
    
    
        transform(strInput.begin(),strInput.end(),strInput.begin(),tolower);
        cout << "The string converted to lower case is: " << endl;
        cout << strInput << endl << endl;
    
    
        return 0;
    }
    i get several errors:
    "C:\Users\Joaquim\Documents\CodeBlocks\test\main.cpp|16|error: no matching function for call to 'transform(std::basic_string<char>::iterator, std::basic_string<char>::iterator, std::basic_string<char>::iterator, <unresolved overloaded function type>)'|"
    so seems these book isn't the best
    but can anyone advice me?

  2. #2
    Join Date
    Apr 1999
    Posts
    27,427

    Re: about Standard Template Library(uppercase and lowcase)

    Quote Originally Posted by Cambalinho View Post
    so the Standard Template Library isn't portable\ANSI?
    i'm studing C++ using the Teach Your Self C++ in 1 Hour a Day. but seems these code isn't correct for GNU compiler:
    The code is not correct because

    1) you did not #include the header where toupper and tolower are declared
    Code:
    #include <cctype>
    http://www.cplusplus.com/reference/cctype/

    and 2) you are not using the toupper and tolower functions that are defined in the global namespace:
    Code:
    transform(strInput.begin(),strInput.end(),strInput.begin(), ::toupper);
    
    transform(strInput.begin(),strInput.end(),strInput.begin(),::tolower);
    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Apr 1999
    Posts
    27,427

    Re: about Standard Template Library(uppercase and lowcase)

    Quote Originally Posted by Cambalinho View Post
    so the Standard Template Library isn't portable\ANSI?
    Of course it's portable because it's part of the ANSI standard document. If a compiler says it is ANSI standard, then it must come with STL library as per the standard. It doesn't matter if the compiler is on Windows, UNIX, Macintosh, a mainframe, etc. If the compiler says it is an ANSI standard C++ compiler, it must come with an STL implementation.

    Regards,

    Paul McKenzie

  4. #4
    Join Date
    Apr 2009
    Posts
    636

    Re: about Standard Template Library(uppercase and lowcase)

    Quote Originally Posted by Paul McKenzie View Post
    The code is not correct because

    1) you did not #include the header where toupper and tolower are declared
    Code:
    #include <cctype>
    http://www.cplusplus.com/reference/cctype/

    and 2) you are not using the toupper and tolower functions that are defined in the global namespace:
    Code:
    transform(strInput.begin(),strInput.end(),strInput.begin(), ::toupper);
    
    transform(strInput.begin(),strInput.end(),strInput.begin(),::tolower);
    Regards,

    Paul McKenzie
    sorry i just copy the code from the book. the book don't speak about it
    now i put something in pdf for i don't forget that.
    thanks for all

  5. #5
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,272

    Re: [RESOLVED] about Standard Template Library(uppercase and lowcase)

    Quote Originally Posted by Cambalinho
    so the Standard Template Library isn't portable\ANSI?
    No, insofar as it has been integrated into the C++ standard library, it is indeed part of standard C++.

    Quote Originally Posted by Cambalinho
    i get several errors:
    "C:\Users\Joaquim\Documents\CodeBlocks\test\main.cpp|16|error: no matching function for call to 'transform(std::basic_string<char>::iterator, std::basic_string<char>::iterator, std::basic_string<char>::iterator, <unresolved overloaded function type>)'|"
    so seems these book isn't the best
    but can anyone advice me?
    You should #include <cctype>. However, even after you do so, there's a problem in that there is a function template named toupper (and likewise, tolower) in the std namespace, in addition to the function named toupper (and likewise, tolower) that was inherited from the C standard library. In the event that the header with the function template is indirectly included, the compiler will be unable to determine what you mean when you just write toupper.

    Since the version of toupper inherited from the C standard library should also be available in the global namespace, one way out would be to write ::toupper instead of the unqualified toupper. Likewise, ::tolower instead of tolower.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  6. #6
    Join Date
    Apr 2009
    Posts
    636

    Re: [RESOLVED] about Standard Template Library(uppercase and lowcase)

    Quote Originally Posted by laserlight View Post
    No, insofar as it has been integrated into the C++ standard library, it is indeed part of standard C++.


    You should #include <cctype>. However, even after you do so, there's a problem in that there is a function template named toupper (and likewise, tolower) in the std namespace, in addition to the function named toupper (and likewise, tolower) that was inherited from the C standard library. In the event that the header with the function template is indirectly included, the compiler will be unable to determine what you mean when you just write toupper.

    Since the version of toupper inherited from the C standard library should also be available in the global namespace, one way out would be to write ::toupper instead of the unqualified toupper. Likewise, ::tolower instead of tolower.
    thanks for all.. thank you.
    (sorry i recive an error, when i try rate you.. sorry Paul McKenzie, you too)

  7. #7
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,360

    Re: [RESOLVED] about Standard Template Library(uppercase and lowcase)

    i'm studing C++ using the Teach Your Self C++ in 1 Hour a Day.
    What version of the book are you using? If you are using edition 7 (May 2012) - the latest published version - then this only gets a 1 or 2 star rating (out of 5) with a lot of errors in the code - like that which you have just encountered! Also note that it only covers those parts of the c++11 standard as implemented by Microsoft Visual Studio - not the full c++11 standard as implemented in gcc. Some people quite like the concept of learning broken down into 1 hour 'chunks' but IMO there are better c++11 books now available.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  8. #8
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,360

    Re: [RESOLVED] about Standard Template Library(uppercase and lowcase)

    so the Standard Template Library isn't portable\ANSI?
    As Paul stated in post #3, any ANSI compilant c++ compiler must come with a STL. However, different compilers come with different implementions of the STL. The implementation of the STL that comes with the gcc compiler will be different from that which comes with Microsoft Visual c++. Though they will provide the same functionality as defined by the standard, they way they achive this will differ. eg the the algorithm used to allocate more capacity to a vector when trying to push new elements is different between the different vendors.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  9. #9
    Join Date
    Apr 2009
    Posts
    636

    Re: [RESOLVED] about Standard Template Library(uppercase and lowcase)

    Quote Originally Posted by 2kaud View Post
    As Paul stated in post #3, any ANSI compilant c++ compiler must come with a STL. However, different compilers come with different implementions of the STL. The implementation of the STL that comes with the gcc compiler will be different from that which comes with Microsoft Visual c++. Though they will provide the same functionality as defined by the standard, they way they achive this will differ. eg the the algorithm used to allocate more capacity to a vector when trying to push new elements is different between the different vendors.
    yes. now the code works fine
    i love SAMS books, because they have little chapters and is more easy to study, but, true, theres at least that errors
    some books use chapters with 30\40 pages.... it's to much
    but like you said that theres a better books, tell me a book name, please
    thanks for all to all

  10. #10
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,360

    Re: [RESOLVED] about Standard Template Library(uppercase and lowcase)

    but like you said that theres a better books, tell me a book name, please
    I would suggest

    c++ Primer Plus edition 6 2nd printing (January 2012)
    http://www.amazon.co.uk/C-Primer-Plu...sional+c%2B%2B

    Professional c++ (2nd edition)
    http://www.amazon.co.uk/Professional...sional+c%2B%2B

    You might also like
    The c++ Standard Library - A tutorial and reference (2nd edition)
    http://www.amazon.co.uk/Standard-Lib...ds=stl+c%2B%2B

    Also there is
    The c++ Programming Language (4th edition)
    http://www.amazon.co.uk/C-Programmin...sional+c%2B%2B

    For templates, consider
    c++ Templates. The current edition (1) does not cover the new c++11 template features but the 2nd edition coming July 2014 does.
    http://www.amazon.co.uk/C-Templates-...dp_ob_title_bk
    http://www.amazon.co.uk/Templates-Co...sional+c%2B%2B

    Although these do not cover c++11, you will find a lot of useful information in
    the 'Exceptional' range of books by Herb Sutter
    http://www.amazon.co.uk/s/ref=a9_sc_...qid=1378286926

    the books by Stephen Dewhurst
    http://www.amazon.co.uk/s/ref=nb_sb_...2B%2B+dewhurst

    the books by Andrei Alexandrescu
    http://www.amazon.co.uk/Andrei-Alexa...pd_sim_b_bl_12

    the 'effective' range of books by Scott Meyers
    http://www.amazon.co.uk/Scott-Meyers...tt_aut_sim_3_1

    Enjoy!
    Last edited by 2kaud; September 4th, 2013 at 04:34 AM.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  11. #11
    Join Date
    Apr 2009
    Posts
    636

    Re: [RESOLVED] about Standard Template Library(uppercase and lowcase)

    Quote Originally Posted by 2kaud View Post
    I would suggest

    c++ Primer Plus edition 6 2nd printing (January 2012)
    http://www.amazon.co.uk/C-Primer-Plu...sional+c%2B%2B

    Professional c++ (2nd edition)
    http://www.amazon.co.uk/Professional...sional+c%2B%2B

    You might also like
    The c++ Standard Library - A tutorial and reference (2nd edition)
    http://www.amazon.co.uk/Standard-Lib...ds=stl+c%2B%2B

    Also there is
    The c++ Programming Language (4th edition)
    http://www.amazon.co.uk/C-Programmin...sional+c%2B%2B

    For templates, consider
    c++ Templates. The current edition (1) does not cover the new c++11 template features but the 2nd edition coming July 2014 does.
    http://www.amazon.co.uk/C-Templates-...dp_ob_title_bk
    http://www.amazon.co.uk/Templates-Co...sional+c%2B%2B

    Enjoy!
    and eat very big sandwich of information lol
    thanks for all

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center