Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,395 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,116 people online right now. Registration is fast and FREE... Join Now!




"cout" undeclared problem

 
Reply to this topicStart new topic

"cout" undeclared problem, first chapter C++ for dummies problem

chuckdpt
29 Oct, 2006 - 07:21 AM
Post #1

New D.I.C Head
*

Joined: 29 Oct, 2006
Posts: 2


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

CODE

#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?
User is offlineProfile CardPM
+Quote Post

Nova Dragoon
RE: "cout" Undeclared Problem
29 Oct, 2006 - 07:31 AM
Post #2

The Innocent Shall Suffer, Big Time
Group Icon

Joined: 16 Aug, 2001
Posts: 6,132



Thanked: 7 times
Dream Kudos: 515
Expert In: Python, Linux

My Contributions
add the line
using namespace std;

after your includes
User is offlineProfile CardPM
+Quote Post

CBart21
RE: "cout" Undeclared Problem
29 Oct, 2006 - 08:18 AM
Post #3

New D.I.C Head
*

Joined: 28 Oct, 2006
Posts: 7


My Contributions
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:

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


or...

you can type:

CODE
using namespace std;


after all your header file directives:

CODE

#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:

CODE
std::


off of all your functions.


Hope that helps,

CBart21
User is offlineProfile CardPM
+Quote Post

mattman059
RE: "cout" Undeclared Problem
29 Oct, 2006 - 12:18 PM
Post #4

D.I.C Regular
Group Icon

Joined: 23 Oct, 2006
Posts: 340


Dream Kudos: 175
My Contributions
Try putting

using namespace std;

Before your int main()

either that or you have to do std::cout instead of plain cout.
User is offlineProfile CardPM
+Quote Post

chuckdpt
RE: "cout" Undeclared Problem
29 Oct, 2006 - 01:25 PM
Post #5

New D.I.C Head
*

Joined: 29 Oct, 2006
Posts: 2


My Contributions
Thanks for the help!
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 02:44AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month