草庐IT

double-brace-initialize

全部标签

C++ 精度 : String to Double

在对转换后的字符串执行一些操作后,我遇到了double的问题。#include#include#includeusingnamespacestd;//conversionfunctionvoidconvert(constchar*a,constinti,double&out){doubleval;istringstreamin(a);in>>val;cout并非所有以字符串形式输入的数字都是这种情况,因此错误不是恒定的。它只影响一些数字(34.38似乎是常数)。目前,当我传入a=34.38和i=100时,它会返回:chara--34.38Val-----34.38modifiedval

C++11 统一初始化 : Field initializer is not constant

我正在尝试像这样实例化一组字符串:classPOI{public:...staticconststd::setTYPES{"restaurant","education","financial","health","culture","other"};...}现在,当我这样做时,我得到了这些错误(全部在这一行):error:fieldinitializerisnotconstantstaticconststd::setTYPES{"restaurant","education","financial","health","culture","other"};error:in-class

c++ - 如何在 C++ 中同时为整数、 float 和 double 据类型重载运算符

我正在创建一个二维坐标类(名为“Point”)来帮助我学习C++。我希望能够对Point类对象(例如Point_a+Point_b)执行基本算术运算(+、-、*、/...)。但是,我也希望能够在Points和其他变量类型(int/float/double)之间执行此类操作。这可以使用运算符/函数重载来完成。从我下面的代码(仅添加)可以看出,据我所知,我必须为每个附加变量类型包含两个附加函数,一个用于“Point+int/float/double”形式,一个用于“int/float/double+Point”形式。#includeusingnamespacestd;classPoint{

c++ - 如何将 double 转换为 float 指针?

我正在尝试将double指针转换为float指针,但我不知道正确的方法。这是我的代码#includeintmain(intargc,constchar*argv[]){//insertcodehere...float*f;doubled=10;f=reinterpret_cast(&d);d=20;std::cout我得到以下结果。RESULT:0Programendedwithexitcode:0如何正确地将double指针转换为float指针?ADD:我期望得到的结果是20 最佳答案 考虑:#include#includeusi

c++ - long double C++的范围是多少

这个问题在这里已经有了答案:longdoublevsdouble(3个答案)关闭9年前。C++中longdouble的取值范围是多少?

c++ - 应该使用哪个函数将字符串转换为 long double?

请注意,一般来说,double不同于longdouble。strtod将string转换为double,但是将string转换为longdouble应该使用哪个函数? 最佳答案 在C++03中,使用boost::lexical_cast,或者:std::stringstreamss(the_string);longdoubleld;if(ss>>ld){//itworked}在C99中,使用strtold。在C89中,使用sscanf和%Lg。在C++11中使用stold。关于每个人接受的格式可能存在细微差别,因此请先检查详细信息.

c++ - 为什么 clang++ 报告与 "value stored to ' .. .' during its initialization is never read"的结构化绑定(bind)?

我有以下测试用例:testcase("[room]exits"){auto[center,east,north,south,west]=make_test_rooms();check_eq(center->east(),east);check_eq(center->north(),north);check_eq(center->south(),south);check_eq(center->west(),west+1);}当我编译它时,clang++(clangversion5.0.1(tags/RELEASE_501/final))报告:room.cpp:52:7:note:Valu

当使用node_modules/.bin/webpack时,无法读取未定义的属性(mix.initialize())

我正在尝试编译node_modules/.bin/webpack我得到了这个错误:Mix.initialize();^TypeError:Cannotreadproperty'initialize'ofundefinedatObject.(/home/vagrant/Code/stream/webpack.config.js:9:4)atModule._compile(module.js:570:32)atObject.Module._extensions..js(module.js:579:10)atModule.load(module.js:487:32)attryModuleLoad(m

c++ - 为什么嵌套的initializer_list会导致内存泄漏

最近我将我的项目升级到VisualStudio2013。因此现在可以使用initializer_list功能。我需要在我的单元测试中初始化测试数据。但是我在使用嵌套的initialize_lists时遇到了内存泄漏。#include#includestructTest_Fixture{Test_Fixture():test_data({std::make_shared>(std::vector{0,1}),std::make_shared>(std::vector{2,3,4})}){}std::vector>>test_data;};BOOST_FIXTURE_TEST_CASE(t

c++ - 启用 _GLIBCXX_DEBUG 后,Stringstream 无法使用 double

我正在使用_GLIBCXX_DEBUG模式来帮助查找我的代码中的错误,但我遇到了一个问题,我认为这是库中的一个错误,但希望有人能告诉我我只是做错了什么。这是一个重现问题的简短示例:#define_GLIBCXX_DEBUG#include#includeintmain(intargc,constchar*argv[]){std::ostringstreamostr;ostr如果我注释掉#define,那么输出是(如预期的那样):Result:1.2有了_GLIBCXX_DEBUG定义,但是输出很简单:Result:我已经追踪到流的_M_num_put字段被保留为NULL,这导致在流中抛