我试图使用GCC(测试版本4.5.1,4.6.3,4.8.4)编译此示例程序:
#include <iostream>
#include <iomanip>
#include <ctime>
#include <chrono>
using std::chrono::system_clock;
int main()
{
system_clock::time_point now = system_clock::now();
std::time_t now_c = system_clock::to_time_t(
now - std::chrono::hours(24));
std::cout << "One day ago, the time was "
<< std::put_time(std::localtime(&now_c), "%F %T") << '\n';
}
Run Code Online (Sandbox Code Playgroud)
prog.cpp: In function 'int main()':
prog.cpp:14:18: error: 'put_time' is not a member of 'std'
Run Code Online (Sandbox Code Playgroud)
我想,可能还没有实现.所以我试着检查这个功能的实现状态.我只找到了这个页面:
但我找不到任何笔记put_time或chrono或相似.任何人都可以指向我提供有关此库的实现状态的信息的资源吗?
双方unique_ptr并shared_ptr接受定制的析构函数他们所拥有的对象上调用.但在的情况下unique_ptr,析构函数作为一个模板参数传递类,而类型shared_ptr的自定义析构函数将被指定为一个模板参数的构造函数.
template <class T, class D = default_delete<T>>
class unique_ptr
{
unique_ptr(T*, D&); //simplified
...
};
Run Code Online (Sandbox Code Playgroud)
和
template<class T>
class shared_ptr
{
template<typename D>
shared_ptr(T*, D); //simplified
...
};
Run Code Online (Sandbox Code Playgroud)
我不明白为什么会有这样的差异.需要什么?
我有以下问题涉及迭代使用定义的字符串的关联数组std::map.
-- snip --
class something
{
//...
private:
std::map<std::string, std::string> table;
//...
}
Run Code Online (Sandbox Code Playgroud)
在构造函数中,我使用与字符串数据相关联的字符串键对填充表.在其他地方我有一个方法toString返回一个字符串对象,该对象包含表对象中包含的所有键和相关数据(如key =数据格式).
std::string something::toString()
{
std::map<std::string, std::string>::iterator iter;
std::string* strToReturn = new std::string("");
for (iter = table.begin(); iter != table.end(); iter++) {
strToReturn->append(iter->first());
strToReturn->append('=');
strToRetunr->append(iter->second());
//....
}
//...
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译时,我收到以下错误:
error: "error: no match for call to ‘(std::basic_string<char,
std::char_traits<char>, std::allocator<char> >) ()’".
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释失踪的是什么,我做错了什么?hash_map在用户必须定义散列函数以便能够hash_map与std::string对象一起使用的情况下,我才发现有关类似问题的一些讨论.在我的情况下也可能是类似的东西?
在导出包含与visual studio警告C4251相关的stl类的类之前,有一些问题:例如这个问题或这个问题.我已经阅读过UnknownRoad的优秀解释.
盲目地禁用警告似乎有点危险,尽管它可能是一种选择.包装所有这些std类并导出它们也不是一个真正的选择.它毕竟被称为标准模板库...即,想要提供这些标准类的接口.
如何在我的dll界面中使用stl-classes?什么是常见做法?
我在论坛上听到使用std::function<>原因性能下降.这是真的吗?如果是真的,这是一个很大的性能下降?
我已经习惯了strtod和变种.我想知道为什么stdlib.h没有附带strtoi.为什么整数被排除在这个派对之外?
具体来说,我问为什么没有版本的atoi具有strtod的安全功能.
我试图声明一个priority_queue of nodes,bool Compare(Node a, Node b)用作比较器函数(在节点类之外).
我现在拥有的是:
priority_queue<Node, vector<Node>, Compare> openSet;
Run Code Online (Sandbox Code Playgroud)
出于某种原因,我得到了 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;
Run Code Online (Sandbox Code Playgroud)
我应该如何正确地宣布我的priority_queue?
我正在使用Debian 7.0.0上的CodeBlocks 10.05开发一个C++应用程序.
由于某种原因,以下代码
#include <iostream>
std::vector< int > delaunayDiv(const std::vector< int <T> > & vP, cv::Rect boundRect,
std::vector<int>& triangles, int& numTriangles, bool lookRight);
Run Code Online (Sandbox Code Playgroud)
返回以下错误
error: 'vector' in namespace 'std' does not name a type
Run Code Online (Sandbox Code Playgroud) 采取以下标准段落:
[C++11: 5.3.3/6]:结果sizeof和sizeof...是类型的常量std::size_t.[注意:std::size_t在标准标题<cstddef>(18.2)中定义. - 尾注]
现在:
[C++11: 18.2/6]:该类型size_t是一个实现定义的无符号整数类型,其大小足以包含任何对象的字节大小.
当然,该段落并不要求这size_t是一个定义的类型别名typedef,但由于它明确声明可以通过标准标题提供<cstddef>,我认为我们可以认为如果没有包含它<cstddef>应该删除任何size_t可用的保证.一个程序.
但是,根据第一个引用,我们可以无论如何获得类型的表达式std::size_t.
int main()
{
typedef decltype(sizeof(0)) my_size_t;
my_size_t x = 0; // OK
std::size_t y = 1; // error: 'size_t' is not a member of 'std'
}
Run Code Online (Sandbox Code Playgroud)
std::size_t该程序不可见,但sizeof(0)仍然给我们一个?真?
因此,说它5.3.3/6是有缺陷的,并且它实际上具有"与std::size_t解决的任何类型相同的类型",而不是 std::size_t它本身,这是不正确的吗?
当然,如果 …
有什么用using namespace std?
我想看看Layman的解释.
std ×10
c++ ×9
c++11 ×4
boost ×1
c ×1
c++-chrono ×1
dictionary ×1
dll ×1
gcc ×1
iterator ×1
namespaces ×1
shared-ptr ×1
stdmap ×1
stdvector ×1
stl ×1
unique-ptr ×1
using ×1