On Saturday 03 May 2003 22:01, alan@ibgames.com wrote:
Ah! The eternal discussion - when should the STL be introduced to people learning C++ :)
I think NOW would be perfect. Here are yet a few improvements to Feldman's implementation: #include <iostream> #include <vector> #include <algorithm> #include <iterator> int main() { using std::vector; using std::cout; using std::flush; using std::cin; using std::copy; using std::ostream_iterator; vector<int> array(10); for (int i = 0; i < 10; ++i) { cout << "Enter number: " << flush; cin >> array[i]; } copy(array.begin(), array.end(), ostream_iterator<int>(cout, "\n")); } 1. Yes, vector<> should be used in favor of C style arrays 2. <iomanip> is not needed for std::endl or std::flush 3. '\n' is preferred over std::endl, if stream flushing is not desired 4. (I think) cout is flushed upon destruction, i.e., at program exit 5. 'using' directives should be avoided in global scope 6. global variables should generally be avoided 7. main() returns 0 if not otherwise stated 8. I'm not intending to shine with my implementation, but I do certainly think that the standard library should be studied from the beginning, together with the rest of the language. C++ is not simply 'C with classes'. It is a complete language of its own, with a very powerful standardized library. 9. Besides Lippman-Lajoie, I'd like to push for the following titles: - Stroustrup: The C++ Programming Language, 3rd Edition, Addison-Wesley - Josuttis: The C++ Standard Library, Addison-Wesley -- Ch