Click to See Complete Forum and Search --> : gcc (g++) "#include" only includes backwards compadibility location.


Gogeta_44
11-06-2004, 01:27 AM
I wasn't sure if I should put this in programming or software, but it doesn't really have anything to do with code itself, mainly gcc. Basicly gcc isn't including the correct #include files. It will use anything in /usr/include/c++/3.3.4/backward but not in /usr/include/c++/3.3.4/. "#include <iostream.h>" works but "#include <iostream>" or "#include <string>" doesn't.

bwkaz
11-06-2004, 09:24 AM
Define "doesn't work", please.

How does it fail? With what error messages? What code are you using to test it?

Gogeta_44
11-06-2004, 05:09 PM
Cout and cin don't work in "#include <iostream>" and string dosen't in "#include <string>". Compiler asks you to declare the function cout for instance. #include <iostream.h> works though.

stephen@slackworkz:~/Programming/Tests/c++$ g++ couttext.c++ -o couttest
couttext.c++: In function `int main()':
couttext.c++:4: error: `cout' undeclared (first use this function)
couttext.c++:4: error: (Each undeclared identifier is reported only once for
each function it appears in.)
couttext.c++:5: error: parse error before `}' token

With a simple:
#include <iostream>
main()
{
cout << "Hello World"
}


This might help:
stephen@darkerstar:~$ ls /usr/include/c++/3.3.4/
algorithm complex deque iterator stack
backward/ csetjmp exception limits stdexcept
bits/ csignal exception_defines.h list streambuf
bitset cstdarg ext/ locale string
cassert cstddef fstream map typeinfo
cctype cstdio functional memory utility
cerrno cstdlib i486-slackware-linux/ new valarray
cfloat cstring iomanip numeric vector
ciso646 ctime ios ostream
climits cwchar iosfwd queue
clocale cwctype iostream set
cmath cxxabi.h istream sstream

stephen@darkerstar:~$ ls /usr/include/c++/3.3.4/backward/
algo.h defalloc.h hashtable.h list.h pair.h stream.h
algobase.h deque.h heap.h map.h queue.h streambuf.h
alloc.h fstream.h iomanip.h multimap.h rope.h strstream
backward_warning.h function.h iostream.h multiset.h set.h tempbuf.h
bvector.h hash_map.h istream.h new.h slist.h tree.h
complex.h hash_set.h iterator.h ostream.h stack.h vector.h

Gogeta_44
11-06-2004, 07:13 PM
Oops! I'm really dumb. I forgot "using namespace std;".

bwkaz
11-06-2004, 11:55 PM
No, you forgot:

using std::cout;
using std::cin;

/* .... */

std::string s("your-string"); etc., etc. :p

Pulling in the entire std namespace will (probably) work, but it's the equivalent of attacking a mosquito with a sledgehammer. You'll pull in (at a guess) about 300 classes, symbols, etc., when your program only requires 1 or 2. (The number of symbols pulled in will depend on the number of header files you #include, and which ones they are, also.)