标签: c++-standard-library

std :: lexical_cast - 有这样的事吗?

C++标准库是否定义了此函数,还是必须使用Boost?

我搜索网络除了Boost之外找不到任何东西,但我想我最好问一下这里.

c++ parsing casting std c++-standard-library

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

std :: queue iteration

我需要迭代std::queue.www.cplusplus.com说:

默认情况下,如果没有为特定队列类指定容器类,则使用标准容器类模板deque.

那么我可以以某种方式到达队列的底层deque并迭代它吗?

c++ iteration queue c++-standard-library

67
推荐指数
5
解决办法
12万
查看次数

为什么从C++ 11中删除了std :: pow(double,int)?

在研究计算p ^ q(指数)的有效方法时,其中q是一个整数并且回顾了C++ 98和C++ 11标准,我注意到std::pow(double, int)在C++ 11 中显然已经消除了重载.

在C++ 98 26.5/6中它有double pow(double, int);签名.

在C++ 11 26.8所有我能找到的是重载采取一对float,double或者long double和一个明确的注意,在参数类型积分和双重的混合物的情况下,在pow(double, double)过载应挑选.

这只是对前一个意图的澄清,如果它们在C++ 98中被错误地添加了,它们是否真的在C++ 11中删除了,还是别的?

显然,该pow(double, int)版本提供了一个很好的优化机会,所以它们被删除似乎很奇怪.编译器是否仍然符合标准以提供这样的优化过载?

c++ c++-standard-library c++11

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

如何让IOStream表现更好?

大多数学习C的C++用户都喜欢使用printf/ scanf系列函数,即使他们使用C++进行编码也是如此.

虽然我承认我发现接口方式更好(特别是类似POSIX的格式和本地化),但似乎压倒性的关注是性能.

看看这个问题:

如何加快逐行读取文件的速度

似乎最好的答案是使用fscanf并且C++的ifstream速度始终慢2-3倍.

我认为如果我们能够编译一个"技巧"存储库以提高IOStream的性能,哪些有效,哪些无效,我会觉得很棒.

要考虑的要点

  • 缓冲(rdbuf()->pubsetbuf(buffer, size))
  • 同步(std::ios_base::sync_with_stdio)
  • 区域设置处理(我们可以使用修剪后的区域设置,还是完全删除它?)

当然,欢迎其他方法.

注意:提到了Dietmar Kuhl的"新"实现,但我无法找到有关它的许多细节.以前的引用似乎是死链接.

c++ optimization iostream c++-faq c++-standard-library

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

C++ Filehandling:ios:app和ios之间的区别:吃了吗?

写入文件ios::ateios:app写入文件时有什么区别.
在我看来,ios::app你可以在文件中移动,而ios::ate只能在文件的末尾读/写.它是否正确?

c++ fstream file c++-standard-library

56
推荐指数
4
解决办法
7万
查看次数

删除了 C++20 标准库中的 operator!=

根据cppreferenceoperator!=许多标准库类型的 ,包括std::unordered_map::operator!=和在 C++20 中std::unordered_set::operator!=删除

委员会做出该决定的理由是什么?这不会使比较支持不对称吗?

c++ deprecated c++-standard-library comparison-operators c++20

53
推荐指数
0
解决办法
5011
查看次数

Do std::min(0.0, 1.0) and std::max(0.0, 1.0) yield undefined behavior?

The question is pretty clear. The following gives the reason why I think these expressions might yield undefined behavior. I would like to know whether my reasoning is right or wrong and why.

Short read:

(IEEE 754) double is not Cpp17LessThanComparable since < is not a strict weak ordering relation due to NaN. Therefore, the Requires elements of std::min<double> and std::max<double> are violated.

Long read:

All references follow n4800. Specifications of std::min and std::max are given …

c++ floating-point undefined-behavior c++-standard-library language-lawyer

50
推荐指数
2
解决办法
1287
查看次数

Android ndk std :: to_string支持

我正在使用android NDK r9d和toolchain 4.8但我无法使用std :: to_string函数,编译器抛出此错误:

 error: 'to_string' is not a member of 'std'
Run Code Online (Sandbox Code Playgroud)

android ndk不支持此功能吗?我试着APP_CPPFLAGS := -std=c++11没有运气.

c++ android std c++-standard-library android-ndk

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

转发声明一个STL容器?

是否可以在头文件中转发声明STL容器?例如,请使用以下代码:

#include <vector>

class Foo
{
private:
    std::vector<int> container_;
    ...
};
Run Code Online (Sandbox Code Playgroud)

我希望能够做到这样的事情:

namespace std
{
    template <typename T> class vector;
}

class Foo
{
private:
    std::vector<int> container_;
    ...
};
Run Code Online (Sandbox Code Playgroud)

可以这样做吗?

c++ header c++-standard-library

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

习惯使用std :: rel_ops

使用std::rel_ops将完整的关系运算符集添加到类的首选方法是什么?

文档建议一个using namespace std::rel_ops,但是这似乎是有严重缺陷的,因为这将意味着包括以这种方式实现的类的头也将增加全关系运算符所有其他类与定义operator<operator==,即使是不希望的.这有可能以令人惊讶的方式改变代码的含义.

作为旁注 - 我一直在使用Boost.Operators来做这件事,但我仍然对标准库感到好奇.

c++ idioms c++-standard-library

47
推荐指数
2
解决办法
4313
查看次数