Tag: std

何时需要使用flag -stdlib = libstdc ++?

什么时候需要使用gcc编译时使用flag -stdlib=libstdc++作为编译器和链接器? 编译器是否自动使用libstdc ++? 我在Ubuntu 13.10上使用gcc4.8.2,我想使用c ++ 11标准。 我已经将-std=c++11传递给编译器。

将vector追加到vector的最佳方法

std::vector<int> a; std::vector<int> b; std::vector<int> c; 我想通过将b和c的元素附加到b来连接这三个向量。 这是最好的方法,为什么? 1)通过使用vector::insert : a.reserve(a.size() + b.size() + c.size()); a.insert(a.end(), b.begin(), b.end()); a.insert(a.end(), c.begin(), c.end()); b.clear(); c.clear(); 2)通过使用std::copy : a.reserve(a.size() + b.size() + c.size()); std::copy(b.begin(), b.end(), std::inserter(a, a.end())); std::copy(c.begin(), c.end(), std::inserter(a, a.end())); b.clear(); c.clear(); 3)通过使用std::move (从C++11 ): a.reserve(a.size() + b.size() + c.size()); std::move(b.begin(), b.end(), std::inserter(a, a.end())); std::move(c.begin(), c.end(), std::inserter(a, […]

用自定义比较器在c ++中声明一个priority_queue

我试图声明priority_queue of nodes的priority_queue of nodes ,使用bool Compare(Node a, Node b)作为比较函数(这是在节点类之外)。 我目前拥有的是: priority_queue<Node, vector<Node>, Compare> openSet; 出于某种原因,我收到Error: "Compare" is not a type name 将声明更改为priority_queue <Node, vector<Node>, bool Compare> 给我Error: expected a '>' 我也试过: priority_queue<Node, vector<Node>, Compare()> openSet; priority_queue<Node, vector<Node>, bool Compare()> openSet; priority_queue<Node, vector<Node>, Compare<Node, Node>> openSet; 我应该如何正确地声明我的priority_queue ?

什么是std :: function的性能开销?

我听到在论坛上使用std::function<>会导致性能下降。 这是真的吗? 如果属实,这是一个很大的性能下降?

Android ndk std :: to_string支持

我正在使用android NDK r9d和工具链4.8,但我不能使用std :: to_string函数,编译器会引发此错误: error: 'to_string' is not a member of 'std' android ndk不支持这个function吗? 我尝试APP_CPPFLAGS := -std=c++11没有运气。

将std :: __ cxx11 :: string转换为std :: string

我使用c + + 11,但也有一些没有configuration它的库,需要一些types转换。 特别是我需要一种方法来将std::__cxx11::string转换为常规的std::string ,但是使用谷歌search我找不到一个方法来做到这一点,把(string)放在前面不起作用。 如果我不转换我得到像这样的链接器错误: undefined reference to `H5::CompType::insertMember(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, H5::DataType const&) const'

什么是“使用命名空间标准”的使用?

什么是using namespace std的using namespace std ? 我想在外行看到解释。

C + + 11:更正std ::数组初始化?

如果我初始化一个std ::数组如下,编译器给我一个关于缺less大括号的警告 std::array<int, 4> a = {1, 2, 3, 4}; 这解决了这个问题: std::array<int, 4> a = {{1, 2, 3, 4}}; 这是警告信息: missing braces around initializer for 'std::array<int, 4u>::value_type [4] {aka int [4]}' [-Wmissing-braces] 这只是我的gcc版本中的一个错误,还是故意完成的? 如果是这样,为什么?

我需要closures一个std :: fstream吗?

可能重复: 我需要手动closures一个ifstream吗? 我需要调用fstream.close()还是fstream一个适当的RAII对象,closures销毁的stream? 我有一个方法内的本地std::ofstream对象。 我可以假定文件在退出这个方法后总是closures而不需要调用close? 我找不到析构函数的文档。

为什么你不能把nullptr的地址?

在C ++ 11标准中,我不明白为什么接受nullptr的地址是不允许的,而允许一个接受他们自己的std :: nullptr_t实例的地址。 除了nullptr是一个保留关键字的事实之外,这个决定是否有任何指定的推理呢? 简单地说,因为这让我感到好笑,所以我试图用下面的函数来绕开这个限制: decltype(nullptr)* func(const decltype(nullptr) &nref) noexcept { return const_cast<decltype(nullptr)*>(reinterpret_cast<const decltype(nullptr)*>(&nref)); } 我不得不在参数上使用reinterpret_cast,因为没有它我得到了歇斯底里的错误: error: invalid conversion from 'std::nullptr_t*' to 'std::nullptr_t*' [-fpermissive] 当我通过直接传递nullptr来调用这个函数时,我每次都得到一个不同的地址。 是nullptrdynamic地分配一个地址及时进行比较等? 或者(可能更可能)也许是编译器强制底层对象的临时副本? 当然这些都不是重要的信息,我只是觉得有趣的是为什么这个特定的限制被实现(以及为什么我看到了我的行为)。