public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] Need some c++ help here please:
@ 2002-08-26 14:42 Spider
  2002-08-26 15:15 ` Richard Reich
  2002-08-27  3:11 ` Thomas T. Veldhouse
  0 siblings, 2 replies; 7+ messages in thread
From: Spider @ 2002-08-26 14:42 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 2792 bytes --]


cat hiworld.cpp
#include <iostream.h>
int main(){
        cout << "Hello World" << endl;
        return(0);
}


Old standard, but should work afaik...

gcc -dumpversion
3.2

c++ -dumpversion
3.2



spider@Darkmere> gcc -o hiworld hiworld.cpp
In file included from /usr/include/g++-v32/backward/iostream.h:31,
                 from hiworld.cpp:1:
/usr/include/g++-v32/backward/backward_warning.h:32:2: warning: #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. Examples include substituting the <X> header for the <X.h>
header for C++ includes, or <sstream> instead of the deprecated header
<strstream.h>. To disable this warning use -Wno-deprecated.
/tmp/ccKgk3Jj.o: In function `main':
/tmp/ccKgk3Jj.o(.text+0x13): undefined reference to `std::cout'
/tmp/ccKgk3Jj.o(.text+0x20): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::operator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
/tmp/ccKgk3Jj.o(.text+0x2b): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char>
>&)'
/tmp/ccKgk3Jj.o(.text+0x30): undefined reference to
`std::basic_ostream<char, std::char_traits<char>
>::operator<<(std::basic_ostream<char, std::char_traits<char> >&
>(*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccKgk3Jj.o: In function
`__static_initialization_and_destruction_0(int, int)':
/tmp/ccKgk3Jj.o(.text+0x59): undefined reference to
`std::ios_base::Init::Init[in-charge]()'
/tmp/ccKgk3Jj.o: In function `__tcf_0':
/tmp/ccKgk3Jj.o(.text+0x8a): undefined reference to
`std::ios_base::Init::~Init [in-charge]()'
/tmp/ccKgk3Jj.o(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status

spider@Darkmere> c++ -o hiworld hiworld.cpp                             
                                          /tmp/dd
In file included from /usr/include/g++-v32/backward/iostream.h:31,
                 from hiworld.cpp:1:
/usr/include/g++-v32/backward/backward_warning.h:32:2: warning: #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. Examples include substituting the <X> header for the <X.h>
header for C++ includes, or <sstream> instead of the deprecated header
<strstream.h>. To disable this warning use -Wno-deprecated.




But this works.... . 

Now.. what am I missing here???

//Spider


--
begin  .signature
This is a .signature virus! Please copy me into your .signature!
See Microsoft KB Article Q265230 for more information.
end

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-dev] Need some c++ help here please:
  2002-08-26 14:42 [gentoo-dev] Need some c++ help here please: Spider
@ 2002-08-26 15:15 ` Richard Reich
  2002-08-26 15:18   ` Spider
  2002-08-27  3:11 ` Thomas T. Veldhouse
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Reich @ 2002-08-26 15:15 UTC (permalink / raw
  To: gentoo-dev

ou need to drop the .h.  The header files for the new stl and iostream
libs have been changed for the new standard.  

You'll also need to do 1 of 2 things

using namespace std;
or 
std::cout << "Hello World" << std::endl;

anyway, here are the changes...

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

OR......................
#include <iostream>

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


also gcc doesn't by default link the stl lib to the app.  g++ will.

That should take care of your problems

- Richard Reich

On Mon, 2002-08-26 at 10:42, Spider wrote:
> 
> cat hiworld.cpp
> #include <iostream.h>
> int main(){
>         cout << "Hello World" << endl;
>         return(0);
> }
> 
> 
> Old standard, but should work afaik...
> 
> gcc -dumpversion
> 3.2
> 
> c++ -dumpversion
> 3.2
> 
> 
> 
> spider@Darkmere> gcc -o hiworld hiworld.cpp
> In file included from /usr/include/g++-v32/backward/iostream.h:31,
>                  from hiworld.cpp:1:
> /usr/include/g++-v32/backward/backward_warning.h:32:2: warning: #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. Examples include substituting the <X> header for the <X.h>
> header for C++ includes, or <sstream> instead of the deprecated header
> <strstream.h>. To disable this warning use -Wno-deprecated.
> /tmp/ccKgk3Jj.o: In function `main':
> /tmp/ccKgk3Jj.o(.text+0x13): undefined reference to `std::cout'
> /tmp/ccKgk3Jj.o(.text+0x20): undefined reference to
> `std::basic_ostream<char, std::char_traits<char> >& std::operator<<
> <std::char_traits<char> >(std::basic_ostream<char,
> std::char_traits<char> >&, char const*)'
> /tmp/ccKgk3Jj.o(.text+0x2b): undefined reference to
> `std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
> std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char>
> >&)'
> /tmp/ccKgk3Jj.o(.text+0x30): undefined reference to
> `std::basic_ostream<char, std::char_traits<char>
> >::operator<<(std::basic_ostream<char, std::char_traits<char> >&
> >(*)(std::basic_ostream<char, std::char_traits<char> >&))'
> /tmp/ccKgk3Jj.o: In function
> `__static_initialization_and_destruction_0(int, int)':
> /tmp/ccKgk3Jj.o(.text+0x59): undefined reference to
> `std::ios_base::Init::Init[in-charge]()'
> /tmp/ccKgk3Jj.o: In function `__tcf_0':
> /tmp/ccKgk3Jj.o(.text+0x8a): undefined reference to
> `std::ios_base::Init::~Init [in-charge]()'
> /tmp/ccKgk3Jj.o(.eh_frame+0x11): undefined reference to
> `__gxx_personality_v0'
> collect2: ld returned 1 exit status
> 
> spider@Darkmere> c++ -o hiworld hiworld.cpp                             
>                                           /tmp/dd
> In file included from /usr/include/g++-v32/backward/iostream.h:31,
>                  from hiworld.cpp:1:
> /usr/include/g++-v32/backward/backward_warning.h:32:2: warning: #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. Examples include substituting the <X> header for the <X.h>
> header for C++ includes, or <sstream> instead of the deprecated header
> <strstream.h>. To disable this warning use -Wno-deprecated.
> 
> 
> 
> 
> But this works.... . 
> 
> Now.. what am I missing here???
> 
> //Spider
> 
> 
> --
> begin  .signature
> This is a .signature virus! Please copy me into your .signature!
> See Microsoft KB Article Q265230 for more information.
> end




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-dev] Need some c++ help here please:
  2002-08-26 15:15 ` Richard Reich
@ 2002-08-26 15:18   ` Spider
  2002-08-26 17:12     ` Terje Kvernes
  0 siblings, 1 reply; 7+ messages in thread
From: Spider @ 2002-08-26 15:18 UTC (permalink / raw
  To: Richard Reich; +Cc: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 1633 bytes --]

begin  quote
On 26 Aug 2002 11:15:16 -0400
Richard Reich <rreich@rdrtech.com> wrote:

> ou need to drop the .h.  The header files for the new stl and iostream
> libs have been changed for the new standard.  
> 
> You'll also need to do 1 of 2 things
> 
> using namespace std;
> or 
> std::cout << "Hello World" << std::endl;
> 
> anyway, here are the changes...
Aye, I've covered both those although I'm using legacy compability with
deprecated code here, mostly because of braindead  computerteachers that
insist on it when we have pen+paper programming.   there's something
about learning "bad form" of programming for a start that ticks me off 
;/ 





> 
> #include <iostream>
> using namespace std;
> int main(){
>      cout << "Hello World" << endl;
>       return(0);
> }
> 
according to the ml posts I've read this is bad practice and one should 
use std::cout whenever/wherever there is need of it.  I'm good at bad
practice though ;)

> OR......................
> #include <iostream>
> 
> int main(){
>      std::cout << "Hello World" << std::endl;
>       return(0);
> }
> 
> 
> also gcc doesn't by default link the stl lib to the app.  g++ will.
now this was the real core issue, why it worked with c++ and not with
gcc.. for a while I thought I'd done something very dumb with my system
:)

so thats why it works with c++ and g++ but not with gcc, thanks! :) 



> 
> That should take care of your problems
> 
> - Richard Reich

thanks for the swift response :) 

//Spider

--
begin  .signature
This is a .signature virus! Please copy me into your .signature!
See Microsoft KB Article Q265230 for more information.
end

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-dev] Need some c++ help here please:
  2002-08-26 15:18   ` Spider
@ 2002-08-26 17:12     ` Terje Kvernes
  2002-08-27  8:15       ` Thomas M. Beaudry
  0 siblings, 1 reply; 7+ messages in thread
From: Terje Kvernes @ 2002-08-26 17:12 UTC (permalink / raw
  To: gentoo-dev

Spider <spider@gentoo.org> writes:

> Richard Reich <rreich@rdrtech.com> wrote:
>
> > #include <iostream>
> > using namespace std;
> > int main(){
> >      cout << "Hello World" << endl;
> >       return(0);
> > }
>  
> according to the ml posts I've read this is bad practice and one
> should use std::cout whenever/wherever there is need of it.  I'm
> good at bad practice though ;)

  the point is mostly to avoid cluttering the global namespace with
  identifiers.  you can move the "using namespace <foo>" into a
  containing block if need be:

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

-- 
Terje


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-dev] Need some c++ help here please:
  2002-08-26 14:42 [gentoo-dev] Need some c++ help here please: Spider
  2002-08-26 15:15 ` Richard Reich
@ 2002-08-27  3:11 ` Thomas T. Veldhouse
  1 sibling, 0 replies; 7+ messages in thread
From: Thomas T. Veldhouse @ 2002-08-27  3:11 UTC (permalink / raw
  To: Spider; +Cc: gentoo-dev

The standard way to do it these days is to use the standard library, which is 
in the standard namespace.

You should probably only use the parts of the standard namespace that you need 
to avoid namespace collisions.  So ...

#include <iostream>
using std::cout;
using std::endl;
// you could comment out the above to lines if you are lazy and uncomment 
// the following line
// using namespace std;

int main(int, char**) {
	cout << "Hello World" << endl;
	return 0;
}

Tom Veldhouse
veldy@veldy.net

On Monday 26 August 2002 09:42 am, Spider wrote:
> cat hiworld.cpp
> #include <iostream.h>
> int main(){
>         cout << "Hello World" << endl;
>         return(0);
> }
>
>
> Old standard, but should work afaik...
>
> gcc -dumpversion
> 3.2
>
> c++ -dumpversion
> 3.2
>
>
>
> spider@Darkmere> gcc -o hiworld hiworld.cpp
> In file included from /usr/include/g++-v32/backward/iostream.h:31,
>                  from hiworld.cpp:1:
> /usr/include/g++-v32/backward/backward_warning.h:32:2: warning: #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. Examples include substituting the <X> header for the <X.h>
> header for C++ includes, or <sstream> instead of the deprecated header
> <strstream.h>. To disable this warning use -Wno-deprecated.
> /tmp/ccKgk3Jj.o: In function `main':
> /tmp/ccKgk3Jj.o(.text+0x13): undefined reference to `std::cout'
> /tmp/ccKgk3Jj.o(.text+0x20): undefined reference to
> `std::basic_ostream<char, std::char_traits<char> >& std::operator<<
> <std::char_traits<char> >(std::basic_ostream<char,
> std::char_traits<char> >&, char const*)'
> /tmp/ccKgk3Jj.o(.text+0x2b): undefined reference to
> `std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
> std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char>
>
> >&)'
>
> /tmp/ccKgk3Jj.o(.text+0x30): undefined reference to
> `std::basic_ostream<char, std::char_traits<char>
>
> >::operator<<(std::basic_ostream<char, std::char_traits<char> >&
> >
> >(*)(std::basic_ostream<char, std::char_traits<char> >&))'
>
> /tmp/ccKgk3Jj.o: In function
> `__static_initialization_and_destruction_0(int, int)':
> /tmp/ccKgk3Jj.o(.text+0x59): undefined reference to
> `std::ios_base::Init::Init[in-charge]()'
> /tmp/ccKgk3Jj.o: In function `__tcf_0':
> /tmp/ccKgk3Jj.o(.text+0x8a): undefined reference to
> `std::ios_base::Init::~Init [in-charge]()'
> /tmp/ccKgk3Jj.o(.eh_frame+0x11): undefined reference to
> `__gxx_personality_v0'
> collect2: ld returned 1 exit status
>
> spider@Darkmere> c++ -o hiworld hiworld.cpp
>                                           /tmp/dd
> In file included from /usr/include/g++-v32/backward/iostream.h:31,
>                  from hiworld.cpp:1:
> /usr/include/g++-v32/backward/backward_warning.h:32:2: warning: #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. Examples include substituting the <X> header for the <X.h>
> header for C++ includes, or <sstream> instead of the deprecated header
> <strstream.h>. To disable this warning use -Wno-deprecated.
>
>
>
>
> But this works.... .
>
> Now.. what am I missing here???
>
> //Spider



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-dev] Need some c++ help here please:
  2002-08-26 17:12     ` Terje Kvernes
@ 2002-08-27  8:15       ` Thomas M. Beaudry
  2002-08-27  9:20         ` Kim Nielsen
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas M. Beaudry @ 2002-08-27  8:15 UTC (permalink / raw
  To: gentoo-dev

>> #include <iostream>
>> using namespace std;
>> int main(){
>>       cout << "Hello World" << endl;
>>       return(0);
>> }
>
> 
> according to the ml posts I've read this is bad practice and one
> should use std::cout whenever/wherever there is need of it.  I'm
> good at bad practice though ;)

That's people getting carried away with a rule-of-thumb and taking
it to it's black-and-white extreme while forgetting the whole reason
for the rule in the first place.

The more namespaces you have, the more likely you are to confuse
them, thus the rule that objects should be expressed in their
namespace prefixed form.  No problem there.

But what is the point in the above example?  None and the "using
namespace" form works just fine.  In fact it could be the prefered
form on a large program with a simple namespace schema.  The reason
for this is the simple fact that working memory can only hold on
average 12 items.  By not having the objects prefixed with their
namespace you can hold more code in working memory when, for example,
debugging, making the job easier on you.

-- 
Thomas M. Beaudry
k8la / ys1ztm

If at first you don't succeed, work for Microsoft.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-dev] Need some c++ help here please:
  2002-08-27  8:15       ` Thomas M. Beaudry
@ 2002-08-27  9:20         ` Kim Nielsen
  0 siblings, 0 replies; 7+ messages in thread
From: Kim Nielsen @ 2002-08-27  9:20 UTC (permalink / raw
  To: gentoo-dev

On Tue, 2002-08-27 at 10:15, Thomas M. Beaudry wrote:
> But what is the point in the above example?  None and the "using
> namespace" form works just fine.  In fact it could be the prefered
> form on a large program with a simple namespace schema.  The reason
> for this is the simple fact that working memory can only hold on
> average 12 items.  By not having the objects prefixed with their
> namespace you can hold more code in working memory when, for example,
> debugging, making the job easier on you.

It also makes it easier when a lot of developers are working with the
same base code. Some function and class can get the same name and even
parameters.

/Kim



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-08-27  9:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-26 14:42 [gentoo-dev] Need some c++ help here please: Spider
2002-08-26 15:15 ` Richard Reich
2002-08-26 15:18   ` Spider
2002-08-26 17:12     ` Terje Kvernes
2002-08-27  8:15       ` Thomas M. Beaudry
2002-08-27  9:20         ` Kim Nielsen
2002-08-27  3:11 ` Thomas T. Veldhouse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox