# A few questions about C++ now and ~10 years ago

**URL:** <https://forum.kirupa.com/t/a-few-questions-about-c-now-and-10-years-ago/224097>\
**Category:** Uncategorized\
**Created:** [April 28, 2007, 3:04pm UTC](https://forum.kirupa.com/t/a-few-questions-about-c-now-and-10-years-ago/224097 "2007-04-28T15:04:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![szianci](https://avatars.discourse-cdn.com/v4/letter/s/f9ae1b/32.png) [@szianci](https://forum.kirupa.com/u/szianci)\
**Post date:** [April 28, 2007, 3:04pm UTC](https://forum.kirupa.com/t/a-few-questions-about-c-now-and-10-years-ago/224097/1 "2007-04-28T15:04:51Z")

</div>

Hello there. Most of you don’t know who I am, but just to introduce my self:  
I started learning C++ about a week ago. I’m currently on “day 2” on “Sam’s teach yourself C++ in 21 days”. I know I’m slow, but that’s one of the reasons I’m posting here right now! 🙂

You see my issue is that a lot of the examples in the book ([http://newdata.box.sk/bx/c/htm/ch01.htm](http://newdata.box.sk/bx/c/htm/ch01.htm)) does NOT work when trying to compile the program with modern compilers (Turbo C++, Visual C++, Dev-C++).

So I started reading a few newer guides and found out that I needed to type in a few other lines before starting to write the main function of the program.

e.g 1, Sam’s teach yourself (day 1):

#include \<iostream.h\>

int main()  
{  
cout \<\< "Hello World!  
",  
return 0;  
}

-This example “works”, but the compiler suggests that I use the library iostream instead of iostream.h. I got confused but figured that they might have just updated the library, so after a few moments of reading about and finding no good info on this, I just used iostream. Problem solved (after a lot of time spent on trying to find out why this wasn’t working 100% with iostream.h).

e.g 2, Sam’s teach yourself (day 2, just copying now instead):  
p.s: the numbers (e.g: 1:, 2:,) are just line numbers to help the reader and explain later how the lines work.  
[COLOR=#0066ff]  
1: // Listing 2.2 using cout  
2:  
3: #include \<iostream.h\>  
4: int main()  
5: {  
6: cout \<\< "Hello there.  
";  
7: cout \<\< "Here is 5: " \<\< 5 \<\< "  
";  
8: cout \<\< “The manipulator endl writes a new line to the screen.” \<\<  
Âendl;  
9: cout \<\< "Here is a very big number: " \<\< 70000 \<\< endl;  
10: cout \<\< "Here is the sum of 8 and 5: " \<\< 8+5 \<\< endl;  
11: cout \<\< "Here’s a fraction: " \<\< (float) 5/8 \<\< endl;  
12: cout \<\< "And a very very big number: " \<\< (double) 7000 \* 7000 \<\<  
Âendl;  
13: cout \<\< "Don’t forget to replace Jesse Liberty with your name…  
";  
14: cout \<\< "Jesse Liberty is a C++ programmer!  
";  
15: return 0;  
16: }

[/COLOR]-This did not work at all. I got errors here and there, can’t exactly remember where but after getting frustrated I looked for other guides to find out how to write it.  
I found a swedish guide (I’m norwegian, so I understand most of it) and read the first four pages. Most of it was the same as Sam’s guide but some important differences. Here, “iostream” was used as a library on the beginner programs, not “iostream.h”.  
And a function called “using namespace std;” was also used. So I tried to apply this to the code and replace a few lines in the code, and eventually made it work. Here is my code:

// Code starts here  
#include \<iostream\>

using namespace std;

int main()  
{  
cout \<\< “Hello there!” \<\< endl;  
cout \<\< "Here is 5: " \<\< 5 \<\< endl;  
cout \<\< “The manipulator endl writes a new line to the screen” \<\< endl;  
cout \<\< "Here is a very big number: " \<\< 70000 \<\< endl;  
cout \<\< "Here is the sum of 8 and 5: " \<\< 8+5 \<\< endl;  
cout \<\< "Here is a fraction (5/8): " \<\< (float) 5/8 \<\< endl;  
cout \<\< "And a very big number: " \<\< (double) 7000 \* 7000 \<\< endl;  
cout \<\< “Don’t forget to replace Jesse Liberty with your name…” \<\< endl;  
cout \<\< “Andreas is a C++ programmer!” \<\< endl;  
cin.get();  
return 0;  
}  
//Code ends here

As you can see, I’ve replaced a few of the "  
"'s with endl;. Simply because I couldn’t get it to function with "  
"'s everywhere.

Can anyone explain to me why the examples in the “old” Sam’s teach yourself guide won’t compile correctly?

Has the language changed from 1994 to 2007 (which I presume it has)?  
If yes: How has it changed? What’s different?

Can I still use Sam’s teach yourself guide to learn C++?

Thanks in advance, and sorry to make you all read all of this =)

szi
