采取这个简单的程序:
#include <fstream>
int main()
{
std::ifstream in(".");
int x;
if (in)
in >> x;
}
在Redhat 6上,gcc 4.4.7运行没有错误
在Ubuntu 14.04 LTS上,gcc 4.8.2运行没有错误
在Redhat 7上,gcc 4.8.2我得到了:
terminate called after throwing an instance of 'std::ios_base::failure' what(): basic_filebuf::underflow error reading the file Aborted (cored dumped)
我认为这与以下内容有关: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53984
然而,我不明白为什么它适用于Ubuntu。
想法?
答案 0 :(得分:1)
区别不在于编译器,区别在于C ++库。其中一个有libstdc ++的错误版本,另一个有libstdc ++或libc ++或其他版本的工作版本。
答案 1 :(得分:0)
我刚刚在我的Trusty Tahr系统上测试过。它就像红帽一样爆炸了。所以它并没有在Ubuntu&#34;上工作。
要验证我们是否获得了相同的结果,这里是我使用过的各种命令的输出:
cky@sunflower:~/tmp$ g++ -O2 -Wall -o test test.cc cky@sunflower:~/tmp$ ./test terminate called after throwing an instance of 'std::ios_base::failure' what(): basic_filebuf::underflow error reading the file Aborted (core dumped) cky@sunflower:~/tmp$ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) cky@sunflower:~/tmp$ dpkg -l libstdc++\* Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-======================================-========================-========================-================================================================================== ii libstdc++-4.8-dev:amd64 4.8.2-19ubuntu1 amd64 GNU Standard C++ Library v3 (development files) un libstdc++-4.8-doc <none> <none> (no description available) un libstdc++-dev <none> <none> (no description available) un libstdc++2.10-dev <none> <none> (no description available) un libstdc++2.8-dev <none> <none> (no description available) un libstdc++2.9-dev <none> <none> (no description available) un libstdc++2.9-glibc2.1-dev <none> <none> (no description available) un libstdc++3.0-dev <none> <none> (no description available) ii libstdc++6:amd64 4.8.2-19ubuntu1 amd64 GNU Standard C++ Library v3 un libstdc++6-4.8-dbg <none> <none> (no description available)