Author Topic: learning C++  (Read 991 times)

Faust

  • Member
  • **
  • Posts: 1,223
  • Kudos: 0
learning C++
« on: 11 May 2003, 12:04 »
OK now I'm learning C++ as well as eiffel.
Typing std::cout all the time is annoying, and according to the book I'm using I should be able to avoid this by putting "using std::cout;" or "using namespace std;" at the top of my program just below "int main()" and the "{".  But when I go to do g++ program.cpp I get a compiler error -
Code: [Select]

Is this just because I am using an old compiler?  It's on my Universities Solaris boxes.

Heres the actual (no laughing this is my first day!) file:
Code: [Select]

edit:everything bar the "using" lines is a copy of another file, cout_easy.cpp with the "std::" parts removed, and that compiled fine.

Also is there a nice way to compile it and have the binary come out with the same name as the source file minus the ".cpp"?  It gets annoying having to do "mv a.out [new_name]" all the time.

[ May 11, 2003: Message edited by: Faust ]

Yesterday it worked
Today it is not working
Windows is like that
 -- http://www.gnu.org/fun/jokes/error-haiku.html

slave

  • Member
  • **
  • Posts: 1,136
  • Kudos: 0
    • http://www.fuckmicrosoft.com
learning C++
« Reply #1 on: 11 May 2003, 12:07 »
I hate to break it to you, but that code compiled fine on my computer.

  :confused:

Faust

  • Member
  • **
  • Posts: 1,223
  • Kudos: 0
learning C++
« Reply #2 on: 11 May 2003, 12:09 »
Damn old as Solaris boxes then.  Bah!  When will the computer sciences division invest in a newer gcc/g++?

Thanks Linux User, now I know it's not my fault.  ;)
Yesterday it worked
Today it is not working
Windows is like that
 -- http://www.gnu.org/fun/jokes/error-haiku.html

slave

  • Member
  • **
  • Posts: 1,136
  • Kudos: 0
    • http://www.fuckmicrosoft.com
learning C++
« Reply #3 on: 11 May 2003, 12:15 »
Weeaaak.  What version of gcc do those computers have?  (type g++ --version)

I just sshed to my univ's solaris mainframe and compiled that code just fine on it too.  And I looked hard at it, and I can't figure out what the hell is wrong.  Very odd.

slave

  • Member
  • **
  • Posts: 1,136
  • Kudos: 0
    • http://www.fuckmicrosoft.com
learning C++
« Reply #4 on: 11 May 2003, 12:18 »
quote:
Also is there a nice way to compile it and have the binary come out with the same name as the source file minus the ".cpp"? It gets annoying having to do "mv a.out [new_name]" all the time.


sure.

> g++ -o somename somename.cc

Faust

  • Member
  • **
  • Posts: 1,223
  • Kudos: 0
learning C++
« Reply #5 on: 12 May 2003, 10:57 »
quote:
Weeaaak. What version of gcc do those computers have? (type g++ --version)


u2564793@iwaki g++ --version

2.8.1

u2564793@iwaki
Yesterday it worked
Today it is not working
Windows is like that
 -- http://www.gnu.org/fun/jokes/error-haiku.html

flap

  • Member
  • **
  • Posts: 1,268
  • Kudos: 137
learning C++
« Reply #6 on: 12 May 2003, 14:34 »
I think there's no support for namespaces in that version of g++ (it's about 5 years old). Get your sys admins to upgrade.
"While envisaging the destruction of imperialism, it is necessary to identify its head, which is none other than the United States of America." - Ernesto Che Guevara

http://counterpunch.org
http://globalresearch.ca


solo

  • Member
  • **
  • Posts: 344
  • Kudos: 1
    • http://www.komodolinux.org/
learning C++
« Reply #7 on: 2 June 2003, 03:01 »
probably doesnt support it, but try 'using namespace std;' above and outside the main function.

if that doesnt work, just try omitting all the using statements and try using cout without std:: attached to it. Behind the standards mebbe?
Komodoware, moving Linux to your desktop.
http://www.komodoware.com/