473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

cout not defined !?!

I'm getting an compile error (using cygwin gcc on windows xp) when I
try to compile the following simple program:

#include <iostream>

int main(void) {
cout << "C++ Hello World";
return 0;
}

It says that cout is undefined. Adding the line "using namespace
std;" after the include doesn't fix the problem. Anyone know what's
going on and how I can fix it?

Thanks,
cpp
Jul 22 '05 #1
4 3627
On Thu, 22 Apr 2004 00:48:21 GMT, cppaddict <he***@hello.com> wrote:
I'm getting an compile error (using cygwin gcc on windows xp) when I
try to compile the following simple program:

#include <iostream>

int main(void) {
cout << "C++ Hello World";
return 0;
}

It says that cout is undefined. Adding the line "using namespace
std;" after the include doesn't fix the problem. Anyone know what's
going on and how I can fix it?

Thanks,
cpp


I believe you need the good old std namespace. Try:

std::cout << "C++ Hello World" << std::endl;

or putting "using namespace std;" under your #include
Jul 22 '05 #2
It says that cout is undefined. Adding the line "using namespace
std;" after the include doesn't fix the problem. Anyone know what's
going on and how I can fix it?

Thanks,
cpp


I believe you need the good old std namespace. Try:

std::cout << "C++ Hello World" << std::endl;

or putting "using namespace std;" under your #include


If you take a look at the original post, I say that I've already tried
that, to no avail...

The error message in that case is: "Undefined reference to
std::cout...."

Any other ideas?

Thanks,
cpp

Jul 22 '05 #3
On Thu, 22 Apr 2004 02:40:54 GMT, cppaddict <he***@hello.com> wrote:
It says that cout is undefined. Adding the line "using namespace
std;" after the include doesn't fix the problem. Anyone know what's
going on and how I can fix it?

Thanks,
cpp


I believe you need the good old std namespace. Try:

std::cout << "C++ Hello World" << std::endl;

or putting "using namespace std;" under your #include


If you take a look at the original post, I say that I've already tried
that, to no avail...

The error message in that case is: "Undefined reference to
std::cout...."

Any other ideas?

Thanks,
cpp


Ahh sorry, you have to use the std namespace and use g++ not gcc. I
have your same environment and it works for me.

-joe

Jul 22 '05 #4
cppaddict wrote:
I'm getting an compile error (using cygwin gcc on windows xp) when I
try to compile the following simple program:

#include <iostream>

int main(void) {
cout << "C++ Hello World";
return 0;
}

It says that cout is undefined. Adding the line "using namespace
std;" after the include doesn't fix the problem. Anyone know what's
going on and how I can fix it?


cout is in the std namespace, so you do need to indicate the namespace
("using namespace std;" is one way).

Other than that, there's nothing wrong with the code (except technically
you should also #include <ostream>, though with most compilers it isn't
necessary). My guess is that you're getting a linker error because you
built the program like this:

gcc hello.cpp

instead of like this:

g++ hello.cpp

BTW, I would also recommend you use the flags "-ansi -pedantic -W
-Wall," if you aren't already.

--
Russell Hanneken
rg********@pobox.com
Remove the 'g' from my address to send me mail.
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Philip Lawatsch | last post by:
Hi, I'd like to get rid of all the cout stuff in my code. Following situation: Way over 2000 files, search and replace in all of them is not an option. All of the files include a basic...
19
by: qazmlp | last post by:
I hope comp.lang.c will not find the following question as a complete off-topic. I would like to remove ie.comment out the 'cout' statements during compilation(actually preprocessing) time. ...
12
by: Minti | last post by:
Is std::cout slower than printf When we call printf e.g. in printf(20 format conversion specifications, 20 arguments); Is it faster than the std::cout << { 20 redirections to the output...
6
by: Omid | last post by:
Hi. I have problems when I try to redirect everything that is sent to cout to a file. I have one piece of code that works and one that does not work. The only difference is which headers I use....
6
by: clilley | last post by:
The following code causes a segmentation fault on DEC Tru64: foo.cc (built into libFoo.so) //--------------------------- include <iostream> bool createFoo() { std::cout << "createFoo" <<...
12
by: Filipe Sousa | last post by:
Hi! Could someone explain to me why this operation is not what I was expecting? int main() { int x = 2; std::cout << x << " " << x++ << std::endl; return 0; }
14
by: Ralf Goertz | last post by:
Hi, this might be intentional, but I don't see a reason, why. Running the program ---------------------- #include <iostream> using namespace std; int main(){
3
by: worlman385 | last post by:
why when I use cout, I must put - using std::cout; #include <iostream> using std::cout; if i look at iostream, it seem cout is defined in iostream - __PURE_APPDOMAIN_GLOBAL extern _CRTDATA2...
11
by: Adrian | last post by:
Is it possible to save a copy of cout the same way you can save a copy of stdout in C (I know C version is portable, but unix portable is good enough for me). I have to use a library which...
58
by: Mark Casternoff | last post by:
I'm getting back into C++ after a long hiatus (they didn't have namespaces back then). I know this question is completely subjective, but I'd be interested in hearing which is the "better"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.