C++程序设计 原理与实践 Hello World std_lib_facilities.h

C++程序设计 原理与实践 Hello World std_lib_facilities.h
作为小白刚开始看《C程序设计 原理与实践 第二版》第2章 Hello World书中的经典程序很简要// hello_world.cpp #include std_lib_facilities.h int main() { cout Hello, World!\n; return 0; }笔者采用的是自带的clang编译器于是直接在命令行中进行编译clang -o hello_world hello_world.cpp然后就是报错未找到头文件std_lib_facilities.h于是到网站www.stroustrup.com把头文件下载下来放在与hello_world.cpp同级目录中于是再次编译clang -o hello_world hello_world.cpp发现还是报错头文件中的代码使用了C11的特性代码于是修改编译命令再次编译clang -stdc11 -stdliblibc -o hello_world hello_world.cpp发现还是报错头文件中找不到ios_base于是修改头文件中代码将//------------------------------------------------------------------------------ #if __GNUC__ __GNUC__ 5 inline ios_base defaultfloat(ios_base b) // to augment fixed and scientific as in C11 { b.setf(ios_base::fmtflags(0), ios_base::floatfield); return b; } #endif //------------------------------------------------------------------------------改为//------------------------------------------------------------------------------ #if __GNUC__ __GNUC__ 5 inline std::ios_base defaultfloat(std::ios_base b) // to augment fixed and scientific as in C11 { b.setf(std::ios_base::fmtflags(0), std::ios_base::floatfield); return b; } #endif //------------------------------------------------------------------------------于是再次编译clang -stdc11 -stdliblibc -o hello_world hello_world.cpp发现还是报错没有指定架构x86_64于是修改命令行再次编译c -stdc11 -stdliblibc -o hello_world hello_world.cpp编译成功。花了一天时间编写Hello World!电脑上没有安装XCode不过有安装最新版的eclipse很可惜的是eclipse在我没有修改头文件代码前也无法正常编译于是我采用了命令行的编译方式。