My compiler says my code isnt standard c++?

#include <iostream.h>

//Decimal To Binary Conversion
//James Duncan Bennet 2007 james.bennet1@ntlworld.com

using namespace std;

void binarynum(int);

int main(void) {
	int intnum;
	int choice = 0;

	cout << endl << "Decimal To Binary Conversion" << endl;

	cout << endl << "Please enter an integer value > 0 : ";
	cin >> intnum;
	if (intnum < 0)
		cout <<  endl << "That isnt an integer > 0!" << endl;
	else {
		cout << intnum << " converted ito binary becomes: ";
		binarynum(intnum);
		cout << endl;
	}

	return 0;
}

void binarynum(int intnum) {
	int remainder;

	if(intnum <= 1) {
		cout << intnum;
		return;
	}

	remainder = intnum%2;
	binarynum(intnum >> 1);
	cout << remainder;
}

To be standard drop the .h after iostream. The iostream header file is different from the iostream.h header, though functionally the are the same (the purists, specialists, experts may be aware of some subtle differences, but for us mere mortals they function the same). iostream, however, is the standard at this time.

>My compiler says my code isnt standard c++?
Your compiler is right.

>#include <iostream.h>
Some people will try to tell you iostream.h is deprecated, but they're wrong. It was never standard to begin with. Since you clearly think you're using the standard iostream anyway, you might as well just hack off the .h and call it good.

thanks, i got rid of .h and it worked fine

excuse me for my confusion, im new to C++, just mishmashed that from books

thanks, i got rid of .h and it worked fine

excuse me for my confusion, im new to C++, just mishmashed that from books

That's the problem with reading outdated books and/or using ancient compilers such as TurboC++. But your compiler seems to be ok, its the lousy book you are reading. Trash it, and buy a new up-to-date book.

yeah, im using code::blocks and MiniGW

i think my book just kinda sucks, its for MS VC++ 5

Can you reccomend any up-to date books for a newbie?

There's a separate thread in the ReadMe section regarding books. However, one common recommendation is "Acceralted C++" and another common suggestion, though some people strongly disagree, is "Teach Yourself C++ in 21 Days". There is no one book that everyone agrees on, so take a look at the recommendations, and then go to book store (if you can) and browse each one you'd consider for a few minutes before you take the plunge.

Member Avatar for iamthwee

I'd go for the teach yourself books in # hours/minutes.

ill take a look at Acceralted C++ - i dont like the "in 21 days" books - the only one of them which i ever got on with was the SQL one, that was excellent

Member Avatar for iamthwee

Yeah I got a php+mysql+apache one and that was excellent.

if you are interested in php, mysql, apache i liked "How to do everything PHP MySQL" its written by an indian guy but its flawless and a good primer.

Member Avatar for iamthwee

I found the sams book to give a very good coverage of the cores topics. Forums, covers the rest.

But thanx for your suggestion bennet.

>ill take a look at Acceralted C++ - i dont like the "in 21 days" books - the only one of them which i ever got on with was the SQL one, that was excellent

I bought accelerated c++ a few months (I think) ago and it is awesome. Unlike the previous c++ books I've bought, accelerated c++ actually teaches you how to program, not just the syntax. I can honestly say that every single program used as examples in accelerated c++ solves a real (sorta) problem.

good i like those ones like that (i like the step by step range for MS .NET) ill se if i can get Accelerated c++ from libary

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.