Stop Microsoft

Miscellaneous => Programming & Networking => Topic started by: Faust on 11 May 2003, 12:04

Title: learning C++
Post by: Faust 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 ]

Title: learning C++
Post by: slave on 11 May 2003, 12:07
I hate to break it to you, but that code compiled fine on my computer.

  :confused:
Title: learning C++
Post by: Faust 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.  ;)
Title: learning C++
Post by: slave 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.
Title: learning C++
Post by: slave 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
Title: learning C++
Post by: Faust 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
Title: learning C++
Post by: flap 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.
Title: learning C++
Post by: solo 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?