Okay so I'm trying to learn the basics of C++ from a book which is I think, well I know, a few years old. I already came across a couple of problems;

Firstly the <iosteam.h> thing, which can technically be rectified by using -wno- deprecated in my djgpp compiler, but i read online a bit and saw people saying "just use <iostream>" which didin't work until I added, the 'using namespace std' sub header. I wondered if anyone could tell me what 'using namespace std;' means and whether using that with taking the .h off the iostream is like a straight swap as it were, so far it has served me well, but I can imagine I could run into problems if, in my book its telling me to use other .h headers or something, and just putting 'using namespace std;' wont cut it anymore. (Yes I am a complete and utter novice sorry).

Problem I have now, could even be related to the problem above, I've copied everything word for word (apart from <iostream.h>), and I'm getting an error message, and I've hit a wall where I literally don't know what to do to rectify it, here is the code and the error message, I have put the error message actually in the code next to the lines the compiler has problems with, it's on line 26 and 27 I think, you shouldn't miss it. I hope someone can help!!!!! Thanks in advance :D Paul.


[
/*enum.cpp 22/06/2008 enumerated types demo**/


#include <iostream>
using namespace std;

//delcare a new enumerated type 'days'
enum days
{
Saturday,//Saturday = 0 by default
Sunday = 0,//force sunday to be 0, default would be 1
Monday,//monday now 1, and each following day +1
Tuesday,
Wednesday,
Thursday,
Friday
} today;//declare a new variable 'today' of type 'days'

int main()
{
//declare two more 'days' objects
days yesterday, tomorrow;

//assign some values and print
today = Tuesday;
yesterday = today-1;//**Here's the error 'Invalid conversion from 'int' to 'days' '
tomorrow = today+1;//**And this line too 'Invalid conversion from 'int' to 'days' '
cout<<"\nToday is "<<today;
cout<<"\nYesterday was "<<yesterday;
cout<<"\nTomorrow will be "<<tomorrow;
return 0;

}

]

Recommended Answers

All 6 Replies

I believe you got to declare what today is.

I believe you got to declare what today is.

He already did.

I believe this is one of the reasons I like Java's enumeration-class better than C++'s enumeration type.

You can't convert an int into an enum, unfortunately.

Hi Pikachumanson, so do you think he made a typr writing the book? I thought that having today just after that enumerator bit it was kind of declaring it along with that? I'll have a play around with that bit anyway see what I can do, Thanks.

haha and I made a typo myself, so Alex you are saying there is no way around this ? I eve used the compiler that the guy said to use at the start of the book, I can't see how he got it wrong ? Thanks.

Thanks Alex, I'll read and see if i can sort myself out!

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.