小编Vin*_*ent的帖子

如何在标准C/C++中获取文件分隔符号:/或\?

我想写一个函数:

inline char separator()
{
    /* SOMETHING */
}
Run Code Online (Sandbox Code Playgroud)

在标准C/C++/C++ 11中返回系统的文件分隔符?(我的意思是斜杠或反斜杠取决于系统).有没有办法实现这个目标?

c c++ filesystems file c++11

23
推荐指数
5
解决办法
4万
查看次数

在std :: abs函数上

是否std::abs()为C++ 11中的所有算术类型定义了函数,并且返回|x|时没有近似问题?

一个奇怪的是,与G ++ 4.7, ,std::abs(char),,std::abs(short int) 和似乎回到了双(对相反:http://en.cppreference.com/w/cpp/numeric/math/abs).如果数字被转换为double,我们可能会对非常大的数字(例如)有一些近似误差.std::abs(int)std::abs(long int)std::abs(long long int)-9223372036854775806LL = 2^63-3

那么我是否std::abs(x)总能|x|为所有算术类型返回保证?

编辑:这是一个进行一些测试的示例程序

#include <iostream>
#include <iomanip>
#include <cmath>
#include <typeinfo>

template<typename T>
void abstest(T x)
{
    static const unsigned int width = 16;
    const T val = x;
    if (sizeof(val) == 1) {
        std::cout<<std::setw(width)<<static_cast<int>(val)<<" ";
        std::cout<<std::setw(width)<<static_cast<int>(std::abs(val))<<" ";
    } else {
        std::cout<<std::setw(width)<<val<<" ";
        std::cout<<std::setw(width)<<static_cast<T>(std::abs(val))<<" ";
    }
    std::cout<<std::setw(width)<<sizeof(val)<<" ";
    std::cout<<std::setw(width)<<sizeof(std::abs(val))<<" ";
    std::cout<<std::setw(width)<<typeid(val).name()<<" …
Run Code Online (Sandbox Code Playgroud)

c++ standards-compliance absolute-value c++11

20
推荐指数
2
解决办法
2万
查看次数

std :: merge和std :: inplace_merge之间的区别?

当在两个连续范围上执行时,复杂性和结果之间有什么区别,std::merge并且std::inplace_merge元素都是不同的?(我不是母语为英语的人,我不确定清楚地了解"inplace"意味着什么)

c++ algorithm stl stl-algorithm c++11

20
推荐指数
1
解决办法
3687
查看次数

C++标准是否要求最大无符号整数的形式为2 ^ N-1?

为了T使std::is_integral<T>::value && std::is_unsigned<T>::valueIS true,不C++标准保证:

std::numeric_limits<T>::max() == 2^(std::numeric_limits<T>::digits)-1
Run Code Online (Sandbox Code Playgroud)

在数学意义上?我正在寻找基于标准引用的证据.

c++ standards unsigned language-lawyer c++11

20
推荐指数
2
解决办法
966
查看次数

解析文本文件中的键值对

我是Python的新手,我搜索如何解析.txt文件.我的.txt文件是一个名单,其计算信息如下:

myfile.txt文件

var0 = 16
var1 = 1.12434E10
var2 = -1.923E-3
var3 = 920

如何读取值并将它们myvar0, myvar1, myvar2, myvar3放在python中?

python file

19
推荐指数
3
解决办法
5万
查看次数

C++ 2011:std :: thread:并行化循环的简单示例?

C++ 2011包含非常酷的新功能,但我找不到很多并行化for循环的例子.所以我非常天真的问题是:如何将一个简单的for循环(如使用"omp parallel for")与std :: thread并行化?(我搜索一个例子).

非常感谢你.

c++ multithreading c++11

19
推荐指数
1
解决办法
3万
查看次数

在g ++/libstdc ++中std :: optional的实现状态?

当我正在开发一个将于2014年左右公开发布的C++库时,我目前正在做出设计选择.使用C++ 14发布的非常有用的工具之一是std::optional.我想知道g++/libstdc++我期望使用哪个版本的版本-std=c++1y.

c++ g++ libstdc++ optional c++14

19
推荐指数
2
解决办法
6298
查看次数

Python:Matplotlib注释换行符(有和没有乳胶)

我有一个非常基本的问题:如何使用"annotate"命令在python中使用matplotlib进行换行.我试过"\"和"\n",但它不起作用.以及如何为"Latex"注释和普通文本注释执行此操作?

非常感谢你.

python latex matplotlib

18
推荐指数
4
解决办法
2万
查看次数

检测立方体和圆锥体是否相互交叉?

考虑3D中的两个几何对象:

  • 与轴对齐并由其中心位置及其范围(边长)定义的立方体
  • 一个不与轴对齐并由其顶点位置定义的圆锥,其底边中心的位置,以及顶点的半角

这是一个用C++定义这些对象的小代码:

// Preprocessor
#include <iostream>
#include <cmath>
#include <array>

// 3D cube from the position of its center and the side extent
class cube
{ 
    public:
        cube(const std::array<double, 3>& pos, const double ext)
        : _position(pos), _extent(ext) 
        {;}
        double center(const unsigned int idim) 
            {return _position[idim];}
        double min(const unsigned int idim)
            {return _position[idim]-_extent/2;}
        double max(const unsigned int idim)
            {return _position[idim]+_extent/2;}
        double extent()
            {return _extent;}
        double volume()
            {return std::pow(_extent, 3);}
    protected:
        std::array<double, 3> _position;
        double _extent;
};

// 3d cone …
Run Code Online (Sandbox Code Playgroud)

c++ python math 3d collision-detection

18
推荐指数
2
解决办法
3198
查看次数

为什么std :: function :: argument_type已被弃用?

我在cppreference上看到了std::function::argument_type在C++ 17 中被弃用的东西.它背后的原因是什么?ISO WG21论文提出了哪些建议?

c++ function deprecated language-lawyer c++17

18
推荐指数
2
解决办法
1741
查看次数