草庐IT

double_it

全部标签

c++ - 微软 nmake : Is it possible to define macros from shell command output?

在使用MicrosoftVisualStudio的nmake编写代码时,我试图将我的SVN修订信息保存到宏中。在GNUmake中,我会做类似的事情:SVN_REVISION=r$(shellsvnversion-n)所以我得到例如:SVN_REVISION=r10001这也可以在Microsoftnmake中实现吗?提前谢谢你。 最佳答案 使用提到的技术以及递归调用make,可以这样完成:!IFNDEFMAKEMAKE=NMAKE!ENDIF!IFNDEFSVN_REVISION!IF[echooff&&FOR/F"usebackq

c++ - 定义最大 double 时,“无法在初始化中将 'double (*)() noexcept' 转换为 'double'”

我读到使用最大double值的标准C++方法是std::numeric_limits::max.然后在我想要将我的double初始化为我使用的最大double的每个函数中:#include#defineMAX_DOUBLE(std::numeric_limits::max)使用gcc-pedantic-pedantic-errors-Wall-Wextra-Werror,我得到以下错误:Cannotconvert'double(*)()noexcept'to'double'ininitialization你能解释一下这个错误吗? 最佳答案

C++ : double iteration through map

我想遍历一个map,但内部循环只会遍历元素的上半部分。使用vector它看起来像这样:for(autoelement1=myVector.begin();element1!=myVector.end();++element1){for(autoelement2=element1+1;element2!=myVector.end();++element2){//mystuff}}但是对于mapelement1+1返回错误nooperatormatchesthisoperand..我相信这是因为元素在map中没有排序.那么我怎样才能正确地做到这一点呢?我目前正在使用这种需要在每个循环中进行

c++ - 使用 fstream 设置精度以输出文件 - double 格式

对于如何使用已打开的fstream将格式化的double输出到文本文件,我找不到答案。目前我的代码是这样做的:intwriteToFile(fstream&f,product_record&p){if(!f){cout其中p是名为product_record的结构,price、tax、sANDh和total都是doubles我试过f但这不起作用。我如何将此double格式设置为小数点后两位的精度。像这样"#.00".我如何使用专门的fstream来实现这一目标?此外,仅供引用,总体任务是简单地读取一个txt文件,将数据存储在一个结构中,将结构添加到一个vector中,然后从结构中读取以

c++ - 统一初始化int* : how can it be forced?

以下代码无法使用clang++3.8.0和g++6.3.0进行编译(编译器标志为-std=c++11-Wall-Wextra-Werror-pedantic-errors):intmain(){int*a=int*{};//doesn'tcompile//^^^^can'tbeparsedasatype(void)a;usingPInt=int*;PIntb=PInt{};//compilessuccessfully//^^^^isparsedasatype(void)b;}这是一种强制编译器以正确方式解释int*{}的方法吗(typedefingofint*是其中一种方式)?

c++ - float 和 double (C++) 的实际最小/最大值是多少

我已阅读关于使用“FLT_MIN”和“FLT_MAX”值作为float的建议。每当我这样做时,codeblocks都会告诉我它的max:3.40282e+038min:1.17549e-038不知道这意味着什么我试图获得真正的值(value)并得到max:47.2498237715min:-34.8045265148...但是这些并没有澄清事情。这是我的代码片段charc;//reserve:1byte,store1character(-128to127)inti;//reserve:4bytes,store-2147483648to2147483657shortints;//rese

c++ - g++ 警告标志以避免 bool 到 double 转换

我寻找g++的警告编译标志,它会阻止从bool到double的静默转换。Thisanswer涉及将int转换为double的更广泛问题。这个问题在那里被驳回了,因为它被认为是无损转换并且完全合法。但是,由于bool具有不同于简单整数的另一种语义含义,我希望从bool到double的隐式转换会发出警告。我试过:-Wall-Wextra-pedantic-Wconversion在以下代码上没有任何成功(没有发出警告):#includeintfoo(doublevar){returnstatic_cast(var);}intmain(){std::cout我使用g++4.9.2,但是建议使用

c++ - long double sqrt() 的精度

我注意到sqrt()的longdouble版本的准确性存在问题。以下代码演示了该问题。#include#include#includeintmain(intargc,char**argv){intcount=0;longdoubles=sqrt(3L);std::cout.precision(21);std::cout编译运行>g++-osqrtsqrt.cpp&&./sqrt给予s=1.73205080756887719318,s^2=2.99999999999999965241.732050807568877193292.999999999999999652841.73205080

C++ 为两个 double 重载 operator%

是否可以为两个double重载operator%?constdoubleoperator%(constdouble&lhs,constdouble&rhs){returnfmod(lhs,rhs);}当然,这会产生错误,因为两个参数之一必须具有类类型。所以我考虑利用C++隐式构造函数调用的可能性来解决这个问题。我是通过以下方式做到的:classMyDouble{public:MyDouble(doubleval):val_(val){}~MyDouble(){}doubleval()const{returnval_;}private:doubleval_;};constdoubleop

c++ - "member of type foo has private copy constructor"错误 : why's it an error?

我试图定义这样一个类:#includeclassmy_class{private:someone_elsesfoo;public:myclass();~myclass();//...};但是编译器失败了:“someone_elses类型的字段foo有一个私有(private)的复制构造函数”。现在我知道我可以通过以下方式解决这个问题:classmy_class{private:someone_elses*foo;//...};my_class::my_class(){foo=newsomeone_elses();}my_class::~my_class(){deletefoo;}我的问