开发者

Header files without .h in C++

开发者 https://www.devze.com 2023-01-08 03:20 出处:网络
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 iostrea

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 mi开发者_运维问答ght 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.


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..


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号