Sign in to follow this  

Purpose of std?

This topic is 4248 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I picked up a book on C++ published around 1999. It teaches projects on the old library header <iostream.h> and it doesn't use the std namespace. However, the book includes a note saying they teach this so that readers that are using older compilers are able to write in it. It says you could use the new standard <iostream> and using namespace std; or you could use the old way, and that the changes are subtle, esoteric, and beyond the scope of the ductory primer. However, when I write the old way I get constant errors when I compile, so now I just write in the new standard. I was just curious as to if maybe it's because my compiler is too new, (Dev C++) or the book is really outdated and you can't write the old standard anymore. Also, what is the purpose of std? Thank you.

Share this post


Link to post
Share on other sites
The purpose of std is to make it easier for programmers. std includes lots of useful templated classes that allows users to utilize commonly used algorithms like linked-lists, strings etc.

There isn't much difference between the old and new std, as far as I know. But maybe someone else can answer that better...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
iostream.h contains legacy C code for streaming input/output(io). The functions should still work just fine if you use them. STL is the standard (std/STL) library for C++. This also includes stream operations, abstract datatypes, the very useful string class, iterators, and common algorithms (sorting, ect). You should use STL library wherever possible, since it has been well tested and is portable. All C functions have been depreciated, but technically you can still use them.

Share this post


Link to post
Share on other sites
The (first) C++ standard is from 1999 so the book must have been written while the standard wasn't published, also most compilers in 1999 didn't support iostream and conformed to the standard. What book is it? It might still be a decent book, but getting a newer one might be a good idea. std is a namespace, you may have read about namespace. It's a way to structure objects and classes where they fit in. So now you can write a mathematical vector and also call it vector, but place it in namespace math. Most newer compilers uses iostream (no .h) and the std namespace, you might get some problems if you ever use VC6 (which you shouldn't, since it's horribly outdated) because it was released before the standarization of C++.

Share this post


Link to post
Share on other sites
It's called "Sam's Teach Yourself C++ Third Edition." And it claims it is Final ANSI/ISO Standard.

Thanks for the help, so I just take it as my compiler doesn't want to read the old library.

Share this post


Link to post
Share on other sites
Quote:
Original post by ItsNotATumaaa
It says you could use the new standard <iostream> and using namespace std; or you could use the old way, and that the changes are subtle, esoteric, and beyond the scope of the ductory primer.

In many ways the differences are not as trivial as the books suggests. You should prefer the new-style (dot-less) headers for all new projects you write.

Quote:
Also, what is the purpose of std?

std is the namespace dedicated to the C++ Standard Library. Much of it comprises the STL, and it even has wrappers that incorporate headers from the C Run-time Library (math.h, time.h, stdio.h, etc.) into the (std) namespace. Because of this, you should prefer to use these wrapper headers (cmath, ctime, cstdio, etc.) for portability reasons.

I haven't read your particular book, but my experience with Sam's is that they generally are not as comprehensive as I'd like - even for a beginner's book. If the book doesn't cover - or only has a mention of - std::string, then I'd probably want to grab a newer/more C++ orientated guide.

Share this post


Link to post
Share on other sites
On the other hand, to someone just starting out, it might be a bit excessive to have to buy one more book. [wink]

You should be able to do ok with the book you've got, just keep in mind that the language has evolved a bit since then, and when the compiler complains, google.

Share this post


Link to post
Share on other sites
Quote:
Original post by ItsNotATumaaa
It's called "Sam's Teach Yourself C++ Third Edition." And it claims it is Final ANSI/ISO Standard.


Sams Teach Yourself C++ is currently in its Fifth Edition, to cover all of the new modifications to the C++ standard. I have the latest one, it covers the latest standard, and is quite good [smile].

Share this post


Link to post
Share on other sites
The one thing in the Standard Library that did change in ways which break much code was the iostream library. You simply MUST use a reference that is modern if you don't want to scream "why the @$!#% doesn't this work, I typed it just like the book!".

That said however, you can simply go to msdn.microsoft.com and go to the MSDN library to do simple reference lookup, or google for better online references.

The core ideas are similar, but the 1999 standard reworked the entire insides of the library (making them template based at their core) and change little esoteric stuff about the modes and overloads ... nothing serious, but enough to cause annoyances.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
iostream.h contains legacy C code for streaming input/output(io).

No it doesn't. It is C++.
Quote:

The functions should still work just fine if you use them. STL is the standard (std/STL) library for C++. This also includes stream operations, abstract datatypes, the very useful string class, iterators, and common algorithms (sorting, ect). You should use STL library wherever possible, since it has been well tested and is portable.

Again, iostream.h was for C++. Pre-standard C++, but still C++. Also, parts of it are quite similar to iostream (cout, cin, etc).

Quote:

All C functions have been depreciated, but technically you can still use them.


No they haven't. Look up the cstdio, cstdlib, etc headers.

Share this post


Link to post
Share on other sites

This topic is 4248 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this