473,320 Members | 1,969 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,320 software developers and data experts.

CX-Post: hello world

I must not be grasping anything here.

Just a simple application, as follows (as any first-program is...)

----
#include <iostream.h>

int main() {
cout <<"hello world";
return 0;
}
----

never compiles! Tried it on FreeBSD, OpenBSD, Windows (under Visual C++ for
Console App), OS X developer tools. THEY ALL complain!
pretty much the same reason too!

/tmp/ccJ31810.o: In function `main':
/tmp/ccJ31810.o(.text+0xf): undefined reference to `cout'
/tmp/ccJ31810.o(.text+0x14): undefined reference to
`ostream::operator<<(char const *)'
collect2: ld returned 1 exit status
But... I thought the #include was supposed to bring in the definitions from
that file before checking the code for execution problems.

I don't understand why it won't work, no matter the tutorials I see, books I
read, articles I read! Can someone point me in the right direction, a
utterly clueless newbie! (yes, I called myself that, so you can call me
that ONCE, too!)

Appreciate it in advance, email is spam-blocked, remove the single period
PRIOR to the @ sign to reply by mail.

--Tim
Jul 22 '05 #1
17 2694
Do this instead:

#include <iostream>
using namespace std;
int main() {
cout << "hello world" << endl;
return 0;
}

iostream.h is deprecated, the standard C++ is to use
iostream without .h

the undefined reference to cout appeared because
the "using namespace std" was not there.

see http://www.research.att.com/~bs/bs_faq2.html

Jul 22 '05 #2
well, you forgot something in ur code..
first C++ standard encourages you to use
#include <iostream>
and cout should really be written as std::cout in your case

if you dont want to write std::cout through out your whole program
you should put
using namespace std;
before your main() function
so that you can just write cout in the following lines

and i also have a question here

can i put the "using namespace bla" in the middle of my code?
or can i make it effective in only a certain block of code??
thank you very much
--
{ Kelvin@!!! }
"Tim Judd" <tj******@hotmail.com> wrote in message
news:ir********************@comcast.com...
I must not be grasping anything here.

Just a simple application, as follows (as any first-program is...)

----
#include <iostream.h>

int main() {
cout <<"hello world";
return 0;
}
----

never compiles! Tried it on FreeBSD, OpenBSD, Windows (under Visual C++ for Console App), OS X developer tools. THEY ALL complain!
pretty much the same reason too!

/tmp/ccJ31810.o: In function `main':
/tmp/ccJ31810.o(.text+0xf): undefined reference to `cout'
/tmp/ccJ31810.o(.text+0x14): undefined reference to
`ostream::operator<<(char const *)'
collect2: ld returned 1 exit status
But... I thought the #include was supposed to bring in the definitions from that file before checking the code for execution problems.

I don't understand why it won't work, no matter the tutorials I see, books I read, articles I read! Can someone point me in the right direction, a
utterly clueless newbie! (yes, I called myself that, so you can call me
that ONCE, too!)

Appreciate it in advance, email is spam-blocked, remove the single period
PRIOR to the @ sign to reply by mail.

--Tim

Jul 22 '05 #3
Do this instead:

#include <iostream>
using namespace std;
int main() {
cout << "hello world" << endl;
return 0;
}

iostream.h is deprecated, the standard C++ is to use
iostream without .h

the undefined reference to cout appeared because
you had iostream.h instead of iostream.

see http://www.research.att.com/~bs/bs_faq2.html

Jul 22 '05 #4
Tim Judd wrote:
I must not be grasping anything here.

Just a simple application, as follows (as any first-program is...)

----
#include <iostream.h>

int main() {
cout <<"hello world";
return 0;
}


There shouldn't be a link error. Did you use
"gcc" instead of "g++" for linking?

--
Regards,
Buster.
Jul 22 '05 #5

"Tim Judd" <tj******@hotmail.com> wrote in message
news:ir********************@comcast.com...
I must not be grasping anything here.

Just a simple application, as follows (as any first-program is...)

----
#include <iostream.h>

int main() {
cout <<"hello world";
return 0;
}
----

never compiles! Tried it on FreeBSD, OpenBSD, Windows (under Visual C++ for Console App), OS X developer tools. THEY ALL complain!
pretty much the same reason too!


[snip]

Clueless tutorials more like. The correct program is

#include <iostream>

int main() {
std::cout <<"hello world";
}

<iostream> not <iostream.h>

std::cout not cout

return is unnecessary (not an error however).

Get a decent book on C++, one that actually contains accurate and up to date
information. I'd make a recommendation but I'd need to what what your
general level of experience with programming is. Do you know any other
languages for instance?

john
Jul 22 '05 #6
> iostream.h is deprecated, the standard C++ is to use
iostream without .h


iostream.h is not deprecated, it is non-standard.

Deprecated implies that it used to be standard, still is standard, but may
become non-standard in the future. iostream.h has never been part of
standard C++.

john
Jul 22 '05 #7
Tim Judd wrote:
I must not be grasping anything here.
*Why* did you cross-post this to comp.lang.c? They don't want to see
your C++ programs over there. I suggest you apologize to that group, and
be more careful in the future.

Just a simple application, as follows (as any first-program is...)

----
#include <iostream.h>
This is not a standard C++ header. Standard C++ uses <iostream>.

int main() {
cout <<"hello world";
cout resides in namespace std. You have to account for that somehow. For
example, you can do this:

std::cout << "hello world\n";

Or this:

using std::cout;
cout << "hello world\n";

Or this:

using namespaces std;
cout << "hello world\n:'

But in any case you need to properly terminate your output with a
newline if you want your code to be correct and portable.
return 0;
}
----


It sounds like you need better tutorials. Most tutorials on the web are
worse than useless. You might try Bruce Eckel's book, "Thinking in C++",
which is free to download.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #8
JaSeong Ju wrote:
Do this instead:
Please watch the cross-post list. Do not cross-post C++ code to comp.lang.c.

#include <iostream>
using namespace std;
int main() {
cout << "hello world" << endl;
return 0;
}

iostream.h is deprecated, the standard C++ is to use
iostream without .h


iostream.h is not deprecated. The standard cannot deprecate what it does
not contain, and iostream.h has never been standard C++.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #9
Please watch the cross-post list. Do not post about C++ in comp.lang.c.

Also, please don't top-post. This is in the FAQ, section 5 (regarding
netiquette).

Kelvin@!!! wrote:
well, you forgot something in ur code..
first C++ standard encourages you to use
#include <iostream>
and cout should really be written as std::cout in your case

if you dont want to write std::cout through out your whole program
you should put
using namespace std;
before your main() function
so that you can just write cout in the following lines

and i also have a question here

can i put the "using namespace bla" in the middle of my code?
or can i make it effective in only a certain block of code??


Yes. It takes effect at the point in the source where it occurs, and
continues until the end of the block in which it occurs, or the end of
the translation unit if it's not inside a block.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #10
Tim Judd wrote:
I must not be grasping anything here.

Just a simple application, as follows (as any first-program is...)

----
#include <iostream.h>

int main() {
cout <<"hello world";
return 0;
}
----

never compiles!


If you are going to post to comp.lang.c, post C. If you want to use
C++, post to comp.lang.c++. For one of the two newsgroups you posted
to, there is no <iostream.h> (or <iostream>) header, there is no
predefined variable cout (or std::cout), and the symbol "<<" is always,
other than in data or comments, a left shift operator. If the line
containing 'cout' is intended to output the text "hello world", then the
behavior of this program would, as well be undefined, since the last
line of output does not end with an end-of-line '\n'.

Here is your code, corrected for comp.lang.c:

#include <stdio.h>
int main(void)
{
puts("Hello world");
return 0;
}

Follow-ups set to comp.lang.c++, since that where your question belongs.
Jul 22 '05 #11
John Harrison wrote:
Clueless tutorials more like. The correct program is

#include <iostream>

int main() {
std::cout <<"hello world";
}


Wrong (you have to output a whole line).

--
Regards,
Buster.
Jul 22 '05 #12
Kevin Goodsell wrote:
Tim Judd wrote:
I must not be grasping anything here.
*Why* did you cross-post this to comp.lang.c? They don't want to see
your C++ programs over there. I suggest you apologize to that group,
and be more careful in the future.


Actually, it has more relevance than you might think. The OP seems to
have compiled and linked his code with a C compiler, maybe because he
doesn't actually know the difference between C and C++. The error
message looks like the typical message you get if you try to link C++
code using gcc instead of g++.
Or this:

using namespaces std;
cout << "hello world\n:'


I don't think that this will work ;-)

Jul 22 '05 #13
In <ir********************@comcast.com> Tim Judd <tj******@hotmail.com> writes:
I must not be grasping anything here.


Most likely, since you appear to be a patent idiot. Otherwise, you'd have
never crossposted your question to comp.lang.c.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Jul 22 '05 #14
"Martin Ambuhl" <ma*****@earthlink.net> wrote in message
news:c5************@ID-227552.news.uni-berlin.de...
Tim Judd wrote:
I must not be grasping anything here.

Just a simple application, as follows (as any first-program is...)

----
#include <iostream.h>

int main() {
cout <<"hello world";
return 0;
}
----

never compiles!
If you are going to post to comp.lang.c, post C. If you want to use
C++, post to comp.lang.c++. For one of the two newsgroups you

posted to, there is no <iostream.h> (or <iostream>) header, there is no
predefined variable cout (or std::cout), and the symbol "<<" is always, other than in data or comments, a left shift operator. If the line
containing 'cout' is intended to output the text "hello world", then the behavior of this program would, as well be undefined, since the last
line of output does not end with an end-of-line '\n'.

Here is your code, corrected for comp.lang.c:

#include <stdio.h>
int main(void)
{
puts("Hello world");
return 0;
}


Just a note: Using Dev-Cpp the OP code compiles and executes.
There is a backward library which contains iostream.h that 1) includes
iostream, and 2) has a bunch of using's for all the iostream
functions.
I am undecided if this is a good thing (allows new users to do dumb
things) or a bad thing (allows new users to do dumb things).
g++ does issue a warning message which reads
#warning This file includes at least one deprecated or antiquated
header. Please consider using one of the 32 headers found in section
17.4.1.2 of the C++ standard. ...
I believe this is all correct behaviour.
--
Gary
Jul 22 '05 #15
Buster <no***@nowhere.com> spoke thus:
Wrong (you have to output a whole line).


If C++ is like C in this respect, it's actually implementation-defined
whether a newline is required (isn't it?).

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #16
Christopher Benson-Manica wrote:
Buster <no***@nowhere.com> spoke thus:
Wrong (you have to output a whole line).


If C++ is like C in this respect, it's actually implementation-defined
whether a newline is required (isn't it?).


Exactly.

--
Regards,
Buster.
Jul 22 '05 #17
Rolf Magnus wrote:
Kevin Goodsell wrote:

Or this:

using namespaces std;
cout << "hello world\n:'

I don't think that this will work ;-)


Heh. Obviously I did actually manage to hit the shift key, but missed
the quote key. After that I probably tried to fix it, and in my usual
fashion hit some lengthy sequence of almost-but-not-quite-right keys,
interspersed with several backspaces, until I had something that
registered in my brain as being correct. Oh, well.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #18

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

Similar topics

10
by: sandSpiderX | last post by:
Hi, What is meant by where X is struct X { int i; } const X cx={1};
2
by: plank | last post by:
Hey Peeps, Ok here is my situation.. I have a Java applet which allows the user to select files and upload them to the server. The applet converts the file to Base64 and then POSTS the data to an...
17
by: jeff | last post by:
Hiya, I would like to be able to read the values in the registers of the x86 type processor, using C. I could do this in ASM but I really want to use C for my project, I havent done anything...
17
by: sgane2001 | last post by:
Hi, I'm using pcre.c to provide regex support for my application software. I want to know how to do 'AND' operation in this. I didn't got any useful info from the net. Is this operator...
2
by: juvi | last post by:
Dim myGraphics As System.Drawing.Graphics Dim buffer As Bitmap Dim fr_bm As Bitmap Dim to_bm As Bitmap Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)...
4
by: empeegee | last post by:
Hi All, I'm going through the Single Unix Specification V3 (POSIX standard) available in the net. In the specification of system interfaces, there are certain parts marked with or . Is those...
2
by: Greg | last post by:
I want to pass a function (testfn) into a another function (fnmeas). testfn makes use of an object cx, so is it ok to have cx local to the file containing testfn ? The fnmeas does not care what...
2
by: .rhavin grobert | last post by:
i have (do try to have?) the following... & = breakpoints in debugger // ---------------------------------------------------------------- // cx.h class CX { public: CX(CX* pcx = NULL);...
5
by: David Golightly | last post by:
Quick question for the gurus out there: in ECMAScript, one can create a new Array object with a length like so: var animals = new Array(128); This creates a new Array object with a "length"...
5
by: Anan18 | last post by:
Hello sir, I'm supposed to Implement and Test the sequence Class Using a Fixed-Sized Array (Chapter 3), from Data Structures & Other objects using c++. The header file is provided, and so is a test...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.