"cout" undeclared problem

first chapter C++ for dummies problem

Page 1 of 1

4 Replies - 4423 Views - Last Post: 29 October 2006 - 02:25 PM Rate Topic: -----

#1 chuckdpt  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 29-October 06

"cout" undeclared problem

Post icon  Posted 29 October 2006 - 08:21 AM

I am reading C++ all in one desk reference for dummies. There is a lesson where you have to type the following:

#include <iostream>
#include <stdlib.h>

int main(int argc, char *argv[])
{
   cout << "Hello, I am your computer talking." << endl;
   system("PAUSE");
   return 0;
}


When I try to compile and run, I get an error message saying "cout" is undeclared.

Any suggestions?

Is This A Good Question/Topic? 0
  • +

Replies To: "cout" undeclared problem

#2 Nova Dragoon  Icon User is offline

  • The Innocent Shall Suffer, Big Time
  • member icon

Reputation: 36
  • View blog
  • Posts: 6,169
  • Joined: 16-August 01

Re: "cout" undeclared problem

Posted 29 October 2006 - 08:31 AM

add the line
using namespace std;

after your includes
Was This Post Helpful? 0
  • +
  • -

#3 CBart21  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 28-October 06

Re: "cout" undeclared problem

Posted 29 October 2006 - 09:18 AM

Since you're just learning C++. Look at the section about Namespaces. All the Standard functions in the header files are inside a Namespace called 'std'.

In order to use the namespace you can use:

std::cout << "Hello, world!";


or...

you can type:

using namespace std;


after all your header file directives:

#include <iostream>
#include <cstdlib>
using namespace std;



That way the std namespace is being used by your program. That will allow you to keep the:

std::


off of all your functions.


Hope that helps,

CBart21
Was This Post Helpful? 0
  • +
  • -

#4 mattman059  Icon User is offline

  • Epic Awesomeness
  • member icon

Reputation: 15
  • View blog
  • Posts: 538
  • Joined: 23-October 06

Re: "cout" undeclared problem

Post icon  Posted 29 October 2006 - 01:18 PM

Try putting

using namespace std;

Before your int main()

either that or you have to do std::cout instead of plain cout.
Was This Post Helpful? 0
  • +
  • -

#5 chuckdpt  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 29-October 06

Re: "cout" undeclared problem

Posted 29 October 2006 - 02:25 PM

Thanks for the help!
Was This Post Helpful? 1

Page 1 of 1