newbie help please

S

Sharad Kala

Angel said:
hi there all, i have started to teach, myself c++, i have found a book
online but one problem, it was written in for use with at the time
mandrake 6 i have mandrake 9.2, at which i thought would work but i am
getting compiler error. i am using gcc to compile it.
here is the code and the error.


#include <iostream.h>

int main()
{
cout << ?Welcome to GNU C++ for Linux programming!? << endl;
return 0;
}


the error is
#warning This file includes at least one deprecated or
antiquated header.

Hi,

#include <iostream.h> is a non-standard header.
The standard header is <iostream> (No .h extension)
Also everything in these headers is wrapped inside the std namespace.
So the correct way to code your program is -

#include <iostream>

int main()
{
std::cout << "Hello World";
return 0;
}

I would recommend "Accelarated C++" by Koenig & Moo.
Check out http://accu.org for book recommendations.

Best wishes,
Sharad
 
S

Sumit Rajan

Angel said:
hi there all, i have started to teach, myself c++, i have found a book
online but one problem, it was written in for use with at the time
mandrake 6 i have mandrake 9.2, at which i thought would work but i am
getting compiler error. i am using gcc to compile it.
here is the code and the error.


#include <iostream.h>

int main()
{
cout << ?Welcome to GNU C++ for Linux programming!? << endl;
return 0;
}


the error is
#warning This file includes at least one deprecated or
antiquated header.

or would it be easier to use borlands c++ compiler as i have
kylix 3 here but i would like to just use gcc. I am using Kate as my
editor .

As the compiler reported you seem to be using an antiquated header. Try
using <iostream> instead of <iostream.h>. You will also need to address the
fact that the Standard Library is defined in a namespace called std.

The following code stands a better chance of compiling without errors:

# include <iostream>

int main()
{
std::cout << "Welcome to GNU C++ for Linux programming!" << std::endl;
return 0;
}

The online book you are using seems to be an old one. If you are trying to
learn C++ and are looking for a free, downloadable book, Bruce Eckel's book
"Thinking in C++" is available at:

http://mindview.net/Books/TICPP/ThinkingInCPP2e.html


Regards,
Sumit.
 
K

Kevin Goodsell

Angel said:
cheers for that copy pasted ur code and got these errors.

"ur"? Regulars on this group put a significant amount of effort into
helping people and answering questions. The least you could do is try to
use proper language when asking for help.
hello.cpp:7:2: warning: no newline at end of file

Yes, a source file should always end with a newline character. Some
systems require text files to end with a newline character.
/home/brendon/tmp/ccNVSvfu.o(.text+0x19): In function `main':
: undefined reference to `std::cout'

I can't readily explain this. If you remembered to #include <iostream>,
then the only explanation I can think of is that your compiler is
installed incorrectly, or was invoked incorrectly. These are not issues
for this group - you might try one of the gnu.help.* groups.
/home/brendon/tmp/ccNVSvfu.o(.text+0x1e): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/home/brendon/tmp/ccNVSvfu.o(.text+0x4a): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/home/brendon/tmp/ccNVSvfu.o(.text+0x79): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/home/brendon/tmp/ccNVSvfu.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

Likewise, the cause of these errors is not apparent, and probably not
related to the language, but rather to your particular implementation.

-Kevin
 
M

Michael James Edukonis

Hello:
Wouldn't "using namespace std;" help to address the namespace issue rather
than using the preface std:: every time?

#include <iostream>
using namespace std;

int main()
{
cout << "Welcome to GNU C++ for Linux programming!" << endl;
return 0;
}

Michael Edukonis

Kevin Goodsell said:
"ur"? Regulars on this group put a significant amount of effort into
helping people and answering questions. The least you could do is try to
use proper language when asking for help.


Yes, a source file should always end with a newline character. Some
systems require text files to end with a newline character.


I can't readily explain this. If you remembered to #include <iostream>,
then the only explanation I can think of is that your compiler is
installed incorrectly, or was invoked incorrectly. These are not issues
for this group - you might try one of the gnu.help.* groups.
std::char_traits said:
(std::basic_ostream said:
/home/brendon/tmp/ccNVSvfu.o(.text+0x4a): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/home/brendon/tmp/ccNVSvfu.o(.text+0x79): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/home/brendon/tmp/ccNVSvfu.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

Likewise, the cause of these errors is not apparent, and probably not
related to the language, but rather to your particular implementation.

-Kevin
 
S

Sumit Rajan

Michael James Edukonis said:
Hello:
Wouldn't "using namespace std;" help to address the namespace issue rather
than using the preface std:: every time?

#include <iostream>
using namespace std;

int main()
{
cout << "Welcome to GNU C++ for Linux programming!" << endl;
return 0;
}

Michael Edukonis

Yes it would address the issue. The down side is that it pollutes the global
namespace. It is - in Stroustrup's words (in TC++PL, Section 3.3) --
"generally in poor taste to dump every name from a namespace into the global
namespace".
 
R

Ron Natalie

Sumit Rajan said:
namespace. It is - in Stroustrup's words (in TC++PL, Section 3.3) --
"generally in poor taste to dump every name from a namespace into the global
namespace".
No, it's poor taste to introduce any symbols into the global namespace of that others
are expected to use (that is, no using directives of any sort in the include files).
If a programmer wants to introduce the entire std namespace into his program, he's
going to have to deal with the implications.
 
S

Sharad Kala

Michael James Edukonis said:
Hello:
Wouldn't "using namespace std;" help to address the namespace issue rather
than using the preface std:: every time?

Hey, you just asked a very debatable question :)
Well I think that one should -
1. Never *ever* write it in a header file.
2. In a program text file if there are many occurrences where one needs to
qualify with std:: then may be it's a good idea to write such a stmt.
3. If say only cout is being used again and again, prefer to use 'using
std::cout;' rather than writing 'using namespace std;'
4. All said, IMO, one should generally avoid to expose the whole std namespace
into one's program.

Best wishes,
Sharad
 
M

Michael James Edukonis

----- Original Message -----
From: "Sharad Kala" <[email protected]>
Newsgroups: comp.lang.c++
Sent: Wednesday, January 21, 2004 10:03 AM
Subject: Re: newbie help please

std::cout;' rather than writing 'using namespace std;'

#3 is an excellent point! thank you very much for that. In school they
teach us to use the preface the first day then "using namespace std;" for
the remainder.

Michael Edukonis
 
S

Sumit Rajan

A classic case of "Do what I say" rather than "Do as I do". Having said do
not do it, Stroustrup proceeds to do exactly that for the remainder of the
1019 pages in the book!

You're right. He doesn't go in for explicit std:: qualifications after this
point. He explains the reason for this in the next line: "However, to keep
short the program fragments used to illlustrate language and library
features, I omit repititive #includes and std:: qualifications".
 
S

Sharad Kala

#3 is an excellent point! thank you very much for that.

You are welcome.
But I think point# 1 is very important, that may not be told in your school
classes.

Best wishes,
Sharad
 
O

osmium

Sumit Rajan writes:

Yes it would address the issue. The down side is that it pollutes the global
namespace. It is - in Stroustrup's words (in TC++PL, Section 3.3) --
"generally in poor taste to dump every name from a namespace into the global
namespace".

A classic case of "Do what I say" rather than "Do as I do". Having said do
not do it, Stroustrup proceeds to do exactly that for the remainder of the
1019 pages in the book!

Now, which of these two options would seem to make more sense for a
beginner? After all, Stroustrup was trying to focus attention on what he
was doing wasn't he? Arcana pollutes the mind and the human mind has only
so many built in registers. I think it is safe to assume that the OP is
not intimately involved in a humungous air traffic control program in which
thousands of lives are at stake; and he has not demostrated that he can not
change his ways later, if and when it becomes necessary.
 
R

Rolf Magnus

Angel said:
# include <iostream>

int main()
{
std::cout << "Welcome to GNU C++ for Linux programming!" <<
std::endl; return 0;
}

The online book you are using seems to be an old one. If you are
trying to
learn C++ and are looking for a free, downloadable book, Bruce
Eckel's book "Thinking in C++" is available at:

http://mindview.net/Books/TICPP/ThinkingInCPP2e.html
cheers for that copy pasted ur code and got these errors.

hello.cpp:7:2: warning: no newline at end of file
/home/brendon/tmp/ccNVSvfu.o(.text+0x19): In function `main':
: undefined reference to `std::cout'
/home/brendon/tmp/ccNVSvfu.o(.text+0x1e): In function `main':
: undefined reference to `std::basic_ostream<char,
: std::char_traits<char> >& std::eek:perator<< <std::char_traits<char>
: >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/home/brendon/tmp/ccNVSvfu.o(.text+0x4a): In function
`__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/home/brendon/tmp/ccNVSvfu.o(.text+0x79): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/home/brendon/tmp/ccNVSvfu.o(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0' collect2: ld returned 1 exit status

Just a shot: Maybe you tried to link your program with gcc instead of
g++?
 
A

Angel

hi there all, i have started to teach, myself c++, i have found a book
online but one problem, it was written in for use with at the time
mandrake 6 i have mandrake 9.2, at which i thought would work but i am
getting compiler error. i am using gcc to compile it.
here is the code and the error.


#include <iostream.h>

int main()
{
cout << ?Welcome to GNU C++ for Linux programming!? << endl;
return 0;
}


the error is
#warning This file includes at least one deprecated or
antiquated header.

or would it be easier to use borlands c++ compiler as i have
kylix 3 here but i would like to just use gcc. I am using Kate as my
editor .

.........
Brendon
 
A

Angel

# include <iostream>

int main()
{
std::cout << "Welcome to GNU C++ for Linux programming!" << std::endl;
return 0;
}

The online book you are using seems to be an old one. If you are trying to
learn C++ and are looking for a free, downloadable book, Bruce Eckel's book
"Thinking in C++" is available at:

http://mindview.net/Books/TICPP/ThinkingInCPP2e.html
cheers for that copy pasted ur code and got these errors.

hello.cpp:7:2: warning: no newline at end of file
/home/brendon/tmp/ccNVSvfu.o(.text+0x19): In function `main':
: undefined reference to `std::cout'
/home/brendon/tmp/ccNVSvfu.o(.text+0x1e): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/home/brendon/tmp/ccNVSvfu.o(.text+0x4a): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/home/brendon/tmp/ccNVSvfu.o(.text+0x79): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/home/brendon/tmp/ccNVSvfu.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,417
Latest member
DarrenGaun

Latest Threads

Top