我正在学习Bjarne的书“编程-原理和使用C++的实践”。在他的书中,他要求包括"std_lib_facilities.h“。所以我得到了这样一部分代码
#ifndef H112
#define H112 020215L
#include<iostream>
#include<iomanip>
#include<fstream>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<list>
#include <forward_list>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include <array>
#include <regex>
#include<random>
#include<stdexcept>
//------------------------------------------------------------------------------
#if __GNUC__ && __GNUC__ < 5
inline ios_base & defaultfloat(ios_base& b) // to augment fixed and scientific as in C++11
{
b.setf(ios_base::fmtflags(0), ios_base::floatfield);
return b;
}
#endifXcode不会编译我的项目并显示错误
在…
inline ios_base & defaultfloat(ios_base& b) 同时也告诉我错误
使用未声明的标识符'ios_base';您的意思是'std::ios_base‘吗?
在…
b.setf(ios_base::fmtflags(0), ios_base::floatfield);所以我把所有的ios_base都改成了std::ios_base,但是它仍然不能编译我的项目.
发布于 2018-10-30 12:49:47
文件里好像有个bug。该部分是“最近”添加,应该只在版本5之前的GCC版本下运行,但是在使用指令之前使用ios_base是不合格的。
“正确”的修复方法是将ios_base的所有使用限定为std::。
inline std::ios_base & defaultfloat(std::ios_base& b)
{
b.setf(std::ios_base::fmtflags(0), std::ios_base::floatfield);
return b;
}或者,您可以在文件中的代码片段之前向上移动using namespace std;语句。这不是一个很好的解决方案,但是Bjarne使用这个头的要点并不是为了演示良好的编码实践,而是为了向初学者隐藏一些复杂性。
在任何情况下,只要您已经取得了足够大的进展,您就应该完全停止使用标头,并正确地执行任务。书告诉你什么时候。
发布于 2020-04-13 03:19:54
作为一个自我指导的学生,t @ravnsgaard在一段时间内一直在寻找这个标题问题的解决方案。只要我在编译过程中引用了C++11,这个解决方案就起作用了:例如,g++ -std=c++11 yourfile.cpp -o yourfile
https://stackoverflow.com/questions/53060662
复制相似问题