tags:

views:

159

answers:

4

I'm having trouble including standard header files like iostream.h and fstream.h. On my system, under usr/include/c++/4.3, none of the files have the ".h" extension (for example, it's just "iostream" not "iostream.h"). That would be fine and dandy, but I'm trying to use another library, DCMTK, which does things like #include<iostream.h>. Unfortunately, there's no such thing as "iostream.h" on my system, only "iostream", meaning my compiler gives me errors like error: iostream.h: No such file or directory.

I guess I could create softlinks from iostream.h to iostream, but that seems like it might create, first of all, troubles down the road, and second of all, be really irritating. Is there another solution?

Just for completeness, the command I'm giving to compile the thing is
g++ -o gc_on_ctp -g -Wall -Idicom/include -Ldicom/lib gc_on_ctp.cpp -ldcmdata
As you can imagine, the header file is located under dicom/include, and the library is under dicom/lib, named libdcmdata.a.

Thanks!

+7  A: 

Just create a new iostream.h file that has a single line in it: #include <iostream>. It seems to be a big mistake by DCMTK because the standard is that there should be no .h in these file names.

Gianni
That's the common solution - Qt uses it among others. It used to be more common because some compilers wouldn't handle files without a .h !
Martin Beckett
Not to be confused with the <cstring> <string.h> headers issue. That's slightly different.
Chris Huang-Leaver
@Chris good point. What I suggest *only* works for file <-> file.h
Gianni
+3  A: 

Those headers are deprecated/pre-standard. On gcc I believe they're located as #include <backward/iostream.h> etc now.

On the other hand if the library you're linking against requires an older incompatible version of the standard library you might have further problems ahead of you.

Mark B
+7  A: 

I would suggest you to take a look here. It explains why and when this iostream.h / iostream was born, why it exists and how you should solve these issues.

Mainly iostream.h is to be considered DEPRECATED UNRELIABLE and IMPLEMENTATION SPECIFIC and using the iostream in place of that one can cause errors..

Jack
`Mainly iostream.h is to be considered DEPRECATED ` Nopes, `<iostream.h>` cannot be considered _deprecated_ because it was never a part of the standard. See Annex D(ISO C++-98) for the list of deprecated features.
Prasoon Saurav
That's a good point. DEPRECATED is not the right term..
Jack
Great, I'll take a look, thanks!
anjruu
+1  A: 

I would fix the (outdated) library. You can use in-place regex search and replace to do that:

perl -e "s/iostream.h/iostream/g;" -pi $(find . -iname "*.cpp")

or

find . -iname "*.cpp" -print0 | xargs -0 sed -i 's/iostream.h/iostream/g'

NOTE: Be careful when doing this... it affects all files recursively from the path you start from.

Amardeep