-
September 3rd, 2013, 10:46 AM
#1
[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?
-
September 3rd, 2013, 10:55 AM
#2
Re: about Standard Template Library(uppercase and lowcase)
Originally Posted by Cambalinho
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
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
-
September 3rd, 2013, 10:58 AM
#3
Re: about Standard Template Library(uppercase and lowcase)
Originally Posted by Cambalinho
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
-
September 3rd, 2013, 11:02 AM
#4
Re: about Standard Template Library(uppercase and lowcase)
Originally Posted by Paul McKenzie
The code is not correct because
1) you did not #include the header where toupper and tolower are declared
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
-
September 3rd, 2013, 11:07 AM
#5
Re: [RESOLVED] about Standard Template Library(uppercase and lowcase)
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++.
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.
-
September 3rd, 2013, 11:13 AM
#6
Re: [RESOLVED] about Standard Template Library(uppercase and lowcase)
Originally Posted by laserlight
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)
-
September 3rd, 2013, 04:07 PM
#7
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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
September 3rd, 2013, 05:25 PM
#8
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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
September 4th, 2013, 03:56 AM
#9
Re: [RESOLVED] about Standard Template Library(uppercase and lowcase)
-
September 4th, 2013, 04:26 AM
#10
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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
September 4th, 2013, 04:31 AM
#11
Re: [RESOLVED] about Standard Template Library(uppercase and lowcase)
Originally Posted by 2kaud
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|