QDateTime::fromMSecsSinceEpoch not works correctly

I'm trying to convert this value (1426519114913) that is a unix timestamp, to QDateTime object. for doing this we have fromMSecsSinceEpoch function in QDateTime that converts msecs from epoch to DateTime object. but I was unsuccessfull, for testing I do below test that it shows me that there is maybe an error with qt, am I forget something? please help me. quint64 timestamp = QDateTime::c

QDateTime :: fromMSecsSinceEpoch无法正常工作

我试图将这个值(1426519114913)(这是一个unix时间戳)转换为QDateTime对象。 为此,我们在QDateTime中使用MSecsSinceEpoch函数将msecs从epoch转换为DateTime对象。 但我没有成功,为了测试我在测试中做了下面的事情,它告诉我,qt可能有错误,我忘记了什么? 请帮帮我。 quint64 timestamp = QDateTime::currentMSecsSinceEpoch(); QDateTime dt3 = QDateTime::fromMSecsSinceEpoch(timestamp); 编辑:错误与调试器的本

Visual Studio is not creating temporary object when typecasting?

I'm using Visual Studio Express 2013 and is fooling around a bit trying to learn about different things in C++. I stumbled upon an interesting bug in the compiler where it doesn't seem to create a temporary object when explicitly type casting to the same type as the reference. #include <iostream> using namespace std; int main() { int number; // float number; number = 2;

类型转换时,Visual Studio不会创建临时对象?

我正在使用Visual Studio Express 2013,并试图在C ++中学习不同的东西。 我偶然发现了编译器中一个有趣的bug,它在明确地将类型转换为与引用类型相同的类型时似乎不会创建临时对象。 #include <iostream> using namespace std; int main() { int number; // float number; number = 2; const int& plainref_i = number; const int& recastref_i = (int)number; // this goes wrong if numbe

How to concatenate a std::string and an int?

I thought this would be really simple but it's presenting some difficulties. If I have std::string name = "John"; int age = 21; How do I combine them to get a single string "John21" ? In alphabetical order: std::string name = "John"; int age = 21; std::string result; // 1. with Boost result = name + boost::lexical_cast<std::string>(age); // 2. with C++11 result = name

如何连接一个std :: string和一个int?

我认为这会很简单,但是会带来一些困难。 如果我有 std::string name = "John"; int age = 21; 我如何将它们结合起来得到一个字符串"John21" ? 按字母顺序排列: std::string name = "John"; int age = 21; std::string result; // 1. with Boost result = name + boost::lexical_cast<std::string>(age); // 2. with C++11 result = name + std::to_string(age); // 3. with FastFormat.Format fastfo

shared takes in a const reference. Any way to get around this?

I am using boost shared pointers in my program, and I have a class that takes as a parameters a reference to another object. The problem I am running into is the make_shared function requires all parameters to be a const reference, and I get compile errors if my class's constructor doesn't allow const reference parameters to be passed in. Does anyone know the reason behind this? Also,

共享需要一个const引用。 任何方式来解决这个问题?

我在我的程序中使用boost共享指针,并且我有一个类作为参数引用另一个对象。 我碰到的问题是make_shared函数要求所有参数都是一个常量引用,如果我的类的构造函数不允许传入const引用参数,我会得到编译错误。 有没有人知道背后的原因? 另外,我能做些什么来解决这个问题吗? 什么是给我的问题的代码示例: class Object { public: Object(int& i) { i = 2; } }; int main(int argc, char *arg

Why is #include <string> preventing a stack overflow error here?

This is my sample code: #include <iostream> #include <string> using namespace std; class MyClass { string figName; public: MyClass(const string& s) { figName = s; } const string& getName() const { return figName; } }; ostream& operator<<(ostream& ausgabe, const MyClass& f) { ausgabe << f.getName();

为什么#include <string>可以防止堆栈溢出错误?

这是我的示例代码: #include <iostream> #include <string> using namespace std; class MyClass { string figName; public: MyClass(const string& s) { figName = s; } const string& getName() const { return figName; } }; ostream& operator<<(ostream& ausgabe, const MyClass& f) { ausgabe << f.getName(); retu

Convert char to int in C and C++

如何在C和C ++中将char转换为int ? Depends on what you want to do: to read the value as an ascii code, you can write char a = 'a'; int ia = (int)a; /* note that the int cast is not necessary -- int ia = a would suffice */ to convert the character '0' -> 0 , '1' -> 1 , etc, you can write char a = '4'; int ia = a - '0'; /* check here if ia is bounded by 0 and 9 */ C and

在C和C ++中将char转换为int

如何在C和C ++中将char转换为int ? 取决于你想要做什么: 要读取ascii代码的值,你可以写 char a = 'a'; int ia = (int)a; /* note that the int cast is not necessary -- int ia = a would suffice */ 要转换字符'0' -> 0 , '1' -> 1等,你可以写 char a = '4'; int ia = a - '0'; /* check here if ia is bounded by 0 and 9 */ C和C ++总是将类型提升为至少int 。 此外,字符文字在C中是int

C++ Functors

I keep hearing a lot about functors in C++. Can someone give me an overview as to what they are and in what cases they would be useful? A functor is pretty much just a class which defines the operator(). That lets you create objects which "look like" a function: // this is a functor struct add_x { add_x(int x) : x(x) {} int operator()(int y) const { return x + y; } private:

C ++ Functors

我一直听到很多关于C ++函数的信息。 有人能给我一个概述,说明它们是什么以及它们会在什么情况下有用? 函子几乎就是定义operator()的类。 这可以让你创建“看起来像”一个函数的对象: // this is a functor struct add_x { add_x(int x) : x(x) {} int operator()(int y) const { return x + y; } private: int x; }; // Now you can use it like this: add_x add42(42); // create an instance of the functor c

explicit & implicit constructors

This question already has an answer here: What does the explicit keyword mean? 11 answers Take this as an example: class complexNumbers { double real, img; public: complexNumbers() : real(0), img(0) { } complexNumbers(const complexNumbers& c) { real = c.real; img = c.img; } complexNumbers( double r, double i = 0.0) { real = r; img = i; } friend void dis

显式和隐式构造函数

这个问题在这里已经有了答案: 显式关键字是什么意思? 11个答案 以此为例: class complexNumbers { double real, img; public: complexNumbers() : real(0), img(0) { } complexNumbers(const complexNumbers& c) { real = c.real; img = c.img; } complexNumbers( double r, double i = 0.0) { real = r; img = i; } friend void display(complexNumbers cx); }; void di

Application of C++ Explicit Constructor

This question already has an answer here: What does the explicit keyword mean? 11 answers An explicit constructor is a function that does not get called in implicit type conversion. For example: class A { A( int a ) {} }; void foo( A a ) {} Here is totally legal to call foo(1) or use any variable of type int or that can be implicitly converted to an int. This is not always desirable

C ++显式构造器的应用

这个问题在这里已经有了答案: 显式关键字是什么意思? 11个答案 显式构造函数是一个函数,它不会在隐式类型转换中被调用。 例如: class A { A( int a ) {} }; void foo( A a ) {} 调用foo(1)或使用int类型的任何变量或可以隐式转换为int类型的函数完全合法。 这并不总是可取的,因为这意味着A可以从整数转换,而不是用整数定义。 添加explicit会避免转换,因此会给你一个编译错误。 一个非显式的单参数构造函

C++ explicit constructor that takes a pointer

This question already has an answer here: What does the explicit keyword mean? 11 answers The following code: void f(Foo) {} int main() { int* p; f(p); } Fails to compile with explicit . Happily compiles without it. live example on godbolt.org

C ++显式构造函数,需要一个指针

这个问题在这里已经有了答案: 显式关键字是什么意思? 11个答案 以下代码: void f(Foo) {} int main() { int* p; f(p); } 无法用explicit编译。 愉快地编译没有它。 在godbolt.org上的现场示例