Purpose of std?

Started by
9 comments, last by Roboguy 17 years, 11 months ago
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.
Advertisement
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...
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.
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++.
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.
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.
:stylin: "Make games, not war.""...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
Your local library should have a much newer book on C++ just grab that. You likely want something after 2001 just to be safe, but the newer the better.

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

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.
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].
------------------------------Support the Blue Skies in Games Campaign!A blog... of sorts.As a general rule, if you don't have a general rule in your signature, you aren't as awesome as someone who does. General rules roxor teh big one one ones.
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.

This topic is closed to new replies.

Advertisement