Is my Old C++ book the problem?

R Old coding practices wrecking my 2010 code?

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 1053 Views - Last Post: 11 March 2010 - 09:11 AM Rate Topic: -----

#1 YmeHuh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 29-September 09

Is my Old C++ book the problem?

Posted 10 March 2010 - 12:39 AM

Whutup All,

I'm am going crazy!

PreCrazy:

So my class text book is very skinny, it's not very thorough and I've been struggling through my C++ course. I'm pretty much a lab behind. So I got some addittional textbooks to hopefully guide me through the areas where I need more explanation.

I have the Deitel guide which is awesome.
And the The Beginner Guide to C++ by WROX is my personal favorite and the one I'm currently trying to use

- now here's the rub.

While I was reading this very detailed guide (WROX)and doing some of the test examples. I notice some code and terms were erm different.

For example

WROX Guide - uses #include <iostream.h> instead of #include <iostream>

or void main() instead of int main()

now all these would be great if it worked...but sometimes they don't and I don't know why.

The fact I found a receipt in the book from 1996 should tell you something.
I don't want to give this book up (It's has the clearest noob level examples)
I even went as far as trying to find an alternate compiler (Code::Blocks) thinking that could be the problem.

Here's the code that has been terrorizing me. It comes up with one freaking error every time "expected ";" before endl"

and I swear I've gone over it with a fine tooth comb. :detective:

I even went as far as to a add std::cout and std::endl to no avail.

Please help.

// Program 2.4
// Ski Combination

#include <iostream>

using std:: cout;
using std ::endl;

int main() 

{

	cout << endl
	<< "The Olympic Games, Lillehamer, Norway"   << endl
	<< "ALPINE SKIING - Combined Slalom Women"   << endl
	<< "21-feb-94" << endl
	
	<< "P. Wilber, NOR" << endl
	<< "Downhill              " << 88.71             << "sec." endl
	<< "Slalom, 1st attempt   " << (138.05 -  88.71) << "sec." endl
	<< "Slalom, 2nd attempt   " << (185.16 - 138.05) << "sec." endl;
	
	return 0;
	
}




Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Is my Old C++ book the problem?

#2 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5246
  • View blog
  • Posts: 27,062
  • Joined: 10-May 07

Re: Is my Old C++ book the problem?

Posted 10 March 2010 - 12:44 AM

This is a favorite topic of NickDMax's.
http://www.dreaminco...howtopic=149914
http://www.dreaminco...howtopic=157900
Was This Post Helpful? 0
  • +
  • -

#3 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: Is my Old C++ book the problem?

Posted 10 March 2010 - 12:55 AM

using std:: cout;
using std ::endl;


Try:
using std::cout;
using std::endl;

Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5246
  • View blog
  • Posts: 27,062
  • Joined: 10-May 07

Re: Is my Old C++ book the problem?

Posted 10 March 2010 - 12:59 AM

Quote

WROX Guide - uses #include <iostream.h> instead of #include <iostream>

This is just simply C vs C++, respectively.
Was This Post Helpful? 0
  • +
  • -

#5 muballitmitte  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 174
  • View blog
  • Posts: 470
  • Joined: 05-November 08

Re: Is my Old C++ book the problem?

Posted 10 March 2010 - 01:09 AM

View Postno2pencil, on 09 March 2010 - 11:59 PM, said:

This is just simply C vs C++, respectively.


Wait. Shouldn`t it be more like standard vs non-standard C++?
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5246
  • View blog
  • Posts: 27,062
  • Joined: 10-May 07

Re: Is my Old C++ book the problem?

Posted 10 March 2010 - 01:11 AM

C uses .h headers & C++ uses, whatever you call the full word without dot h at the end. If that's standard vs non standard, *shrug*, all I know is C uses it one way & C++ uses it the other.

Granted, C++ is backwards compatible (at least with the headers/naming usage), so I don't know if that's standard or not.
Was This Post Helpful? 0
  • +
  • -

#7 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Is my Old C++ book the problem?

Posted 10 March 2010 - 01:35 AM

It is true that C headers end with .h, but not <iostream.h> because iostream is C++. <iostream.h> is deprecated (i.e. old, non-standard) C++.

I believe most C++ compilers will still accept .h headers but give a long whiney warning about using antiquated headers. Maybe some refuse to accept them at all.

void main() is non-standard C and C++. Old compilers like Turbo C++ accepted that; some if not all modern compilers will treat that as an error & won't compile it.

The reason for your "expected ";" before endl" error is that you forgot the << before endl in three places:
        << "Downhill              " << 88.71             << "sec." endl
        << "Slalom, 1st attempt   " << (138.05 -  88.71) << "sec." endl
        << "Slalom, 2nd attempt   " << (185.16 - 138.05) << "sec." endl;



View PostPlasticineGuy, on 10 March 2010 - 02:55 AM, said:

using std:: cout;
using std ::endl;


Try:
using std::cout;
using std::endl;

Those extra blank spaces before and after the scope operators :: don't belong there, but they don't make any difference. The compiler ignores the extra whitespace.
Was This Post Helpful? 1
  • +
  • -

#8 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: Is my Old C++ book the problem?

Posted 10 March 2010 - 01:37 AM

Quote

some if not all modern compilers will treat that as an error & won't compile it.
Every compiler I've used compiles it. It generally throws a whingey warning, but it compiles.
Was This Post Helpful? 0
  • +
  • -

#9 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Is my Old C++ book the problem?

Posted 10 March 2010 - 01:40 AM

Not GCC 4:
test.cc:6: error: ‘::main’ must return ‘int’


Was This Post Helpful? 0
  • +
  • -

#10 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: Is my Old C++ book the problem?

Posted 10 March 2010 - 01:42 AM

Thank goodness. An older version of GCC does (whichever one Dev-C++ 4.9 uses).

Visual C++ compiles it and only throws warnings in strict mode.

Quote from Microsoft:

Quote

we don't give the warning in non-strict mode as unfortunately this is a very common C++ 'mistake'.

http://connect.micro...-give-a-warning

This post has been edited by PlasticineGuy: 10 March 2010 - 01:51 AM

Was This Post Helpful? 0
  • +
  • -

#11 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Is my Old C++ book the problem?

Posted 10 March 2010 - 01:49 AM

GCC 3.3 also refuses to compile void main

Dev-C++ V4 uses MinGW based on gcc 2.95.
Was This Post Helpful? 0
  • +
  • -

#12 barnwillyb  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 108
  • Joined: 22-May 07

Re: Is my Old C++ book the problem?

Posted 10 March 2010 - 03:30 AM

Try this out!

cout << endl << "The Olympic Games, Lillehamer, Norway" << endl
			 << "ALPINE SKIING - Combined Slalom Women" << endl
			 << "21-feb-94" << endl
	
			 << "P. Wilber, NOR" << endl
			 << "Downhill              " << 88.71             << "sec."<< endl
			 << "Slalom, 1st attempt   " << (138.05 -  88.71) << "sec."<< endl
			 << "Slalom, 2nd attempt   " << (185.16 - 138.05) << "sec."<< endl;

This post has been edited by no2pencil: 10 March 2010 - 03:32 AM
Reason for edit:: Removed entire quote

Was This Post Helpful? -1
  • +
  • -

#13 joesyuh  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 174
  • Joined: 30-September 08

Re: Is my Old C++ book the problem?

Posted 10 March 2010 - 06:56 AM

This is the book that I have used for my beginning c++ class and my second c++ class. Good book...

http://www.amazon.co...0QWGSH5TAGAHHJZ
Was This Post Helpful? 0
  • +
  • -

#14 YmeHuh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 29-September 09

Re: Is my Old C++ book the problem?

Posted 10 March 2010 - 08:01 AM

Boom goes the dynamite!

It was among other things

the final "<<" in the 3 places thank you. :bananaman:

Interesting to find out I'm using some old @ss code.

I'm using Xcode on a MacBook.

Can I adjust it some way to be "less strict" to accept some older code conventions?




View Postr.stiltskin, on 10 March 2010 - 12:35 AM, said:

It is true that C headers end with .h, but not <iostream.h> because iostream is C++. <iostream.h> is deprecated (i.e. old, non-standard) C++.

I believe most C++ compilers will still accept .h headers but give a long whiney warning about using antiquated headers. Maybe some refuse to accept them at all.

void main() is non-standard C and C++. Old compilers like Turbo C++ accepted that; some if not all modern compilers will treat that as an error & won't compile it.

The reason for your "expected ";" before endl" error is that you forgot the << before endl in three places:
        << "Downhill              " << 88.71             << "sec." endl
        << "Slalom, 1st attempt   " << (138.05 -  88.71) << "sec." endl
        << "Slalom, 2nd attempt   " << (185.16 - 138.05) << "sec." endl;



View PostPlasticineGuy, on 10 March 2010 - 02:55 AM, said:

using std:: cout;
using std ::endl;


Try:
using std::cout;
using std::endl;

Those extra blank spaces before and after the scope operators :: don't belong there, but they don't make any difference. The compiler ignores the extra whitespace.

This post has been edited by YmeHuh: 10 March 2010 - 08:01 AM

Was This Post Helpful? 0
  • +
  • -

#15 YmeHuh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 29-September 09

Re: Is my Old C++ book the problem?

Posted 10 March 2010 - 08:09 AM

Thank you...!

no2pencil, joesyuh, barnwillyb, PlasticineGuy, r.stiltskin.

Now onto...

Chapt 3.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2