PDA

View Full Version : g++ help



jarg
August 5th, 2005, 11:58 PM
I have no clue how to get g++ to run, I am pretty sure I have all the files installed (I found an old thread), but I really have no clue how to run anything under linux. Any help on running it?

DJ_Max
August 6th, 2005, 01:20 AM
What are you trying to do? Normally, you open a terminal

g++ FILENAME.cpp -o BINNAME

jarg
August 6th, 2005, 02:35 PM
What are you trying to do? Normally, you open a terminal
thanks but I got an error


jared@ubuntu:~$ g++ /home/jared/Desktop/firtprogram.cpp -o BINNAME
In file included from /usr/include/c++/3.3/backward/iostream.h:31,
from /home/jared/Desktop/firtprogram.cpp:3:
/usr/include/c++/3.3/backward/backward_warning.h:32:2: warning: #warning This fi le 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 in clude substituting the <X> header for the <X.h> header for C++ includes, or <sst ream> instead of the deprecated header <strstream.h>. To disable this warning us e -Wno-deprecated.
jared@ubuntu:~$


when running

// my first program in C++

#include <iostream.h>

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

do you know what that means?

cwaldbieser
August 6th, 2005, 05:50 PM
// my first program in C++

#include <iostream.h>

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


Try:

// my first program in C++

#include <iostream>

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

It looks like you just got a warning for using the old-style C++ headers. At the present, the C++ standard library uses "<foo>" includes where you see "<foo.h>" in older references. The namespace (std) is also important once you start using the new headers.

DJ_Max
August 6th, 2005, 08:05 PM
To add to what cwaldbieser said. He means adding

using namespace std;

cwaldbieser
August 6th, 2005, 09:19 PM
To add to what cwaldbieser said. He means adding

using namespace std;

For toy programs, the [using] directive is OK. But once you start writing more complicated programs, it becomes better practice to forgo the [using] directive and just qualify your symbols. Especially in header files that you expect someone else to include. Otherwise, you just end up polluting the namespace.

LordHunter317
August 6th, 2005, 11:32 PM
Or, qualify your symbols on a per-symbol basis, at the smallest reasonable scope (usually function-scope):

#include <iostream>

int main() {
using std::cout;
using std::endl;

cout << "Hello World" << endl;
}