954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Just learning..what is wrong?

Hi everyone, just learning c++ cannot for the life of me work out what is wrong with this code..?

All I am getting is cout , undeclared identifier.

Anyone help?

james6754
Junior Poster
188 posts since Dec 2010
Reputation Points: 50
Solved Threads: 15
 
#include <iostream.h>
#include "stdafx.h"

using namespace std;
//declare stripped down class SimpleCat
     class SimpleCat
     {
public:
            SimpleCat(); //SimpleCat contstructor
             ~SimpleCat(); //SimpleCat destructor
     private:
             int itsAge;
        

        SimpleCat::SimpleCat()
        {
               cout << "Constructor called.\n";
               itsAge = 1;
        }

        SimpleCat::~SimpleCat()
        {
               cout << "Destructor called.\n";
		}
	 };
int main()
        {
               cout << "SimpleCat Frisky...\n";
               SimpleCat Frisky; //Frisky is created on the stack and calls constructor
               cout << "SimpleCat *pRags = new SimpleCat...\n";
               SimpleCat * pRags = new SimpleCat; //SimpleCat pointed to by pRags
               cout << "delete pRags...\n"; 
               delete pRags; //delete is called on pRags – destructor is called
               cout << "Exiting, watch Frisky go...\n";
        return 0; //when the function ends Frisky goes out of scope
}
james6754
Junior Poster
188 posts since Dec 2010
Reputation Points: 50
Solved Threads: 15
 

You forgot the ; on line 6.
The IF in line 8 cannot be in all capital letters.
And you misspelled PRINTF

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

Excuse me? I do not understand what you mean at all...

james6754
Junior Poster
188 posts since Dec 2010
Reputation Points: 50
Solved Threads: 15
 
#include <iostream.h>

Try this instead:

#include <iostream>
gusano79
Posting Pro
521 posts since May 2004
Reputation Points: 182
Solved Threads: 77
 

Think WaltP just posted wrong!

Phillamon
Junior Poster in Training
65 posts since Oct 2010
Reputation Points: 36
Solved Threads: 5
 
Think WaltP just posted wrong!


No, he didn't post the code until after I saw his first and only post at that time.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You