草庐IT

execution-time

全部标签

c++ - 给定范围内的完美正方形 : abnormal execution of loops

程序编号1:在给定的a和b范围内,其中ab,我想找出一个数字是否是一个完美正方形,如果是,则打印其根。因此,我编写了如下代码:#include#include#include#includeusingnamespacestd;floatsquaredroot(intn){floatlow=0.0,mid;floathigh=(float)n+1;while((high-low)>0.00001){mid=(low+high)/2;if(mid*mid>a>>b;floatroo=0.0;for(i=a;i对于给定的输入15,输出应该是2。但是,上面的程序没有打印任何值。然而,当我尝试使

c++ - 使用 std::get_time 将时间字符串转换为 std::time_t:错误结果

我正在尝试按时间顺序对照片进行排序。因此,我从EXIF数据中将时间提取为字符串,然后将其转换为std::time_t。但是我有时会得到不正确的结果。我已将问题简化为这个最小的例子。它具有三个时间字符串,相隔一秒:#include#include#include#include#include#includeintmain(){std::vectorvec;vec.push_back("2016:07:3009:27:06");vec.push_back("2016:07:3009:27:07");vec.push_back("2016:07:3009:27:08");for(auto&

c++ - boost::date_time, g++-4.7.0, 编译错误

以下代码在g++-4.7.0下出现编译错误,但在g++-4.6下编译正常。#include#includeusingnamespacestd;intmain(){boost::posix_time::ptimetime_t_epoch(boost::gregorian::date(1970,1,1));cout下面是反复看到的错误信息(编译器输出了很多信息)/usr/include/boost/date_time/local_time/local_date_time.hpp:433:84:error:useofdeletedfunctionboost::shared_ptr>::sha

c++ - 为什么 std::timed_mutex::try_lock_for 不起作用?

我在Ubuntu12.04中使用gcc-4.8.1(configure:./configure--prefix=/usr/local)编译了以下代码,但是当我运行它时,它没有工作。它没有停下来等待互斥量。它返回false,并输出“Helloworld!”命令:g++-std=c++11main.cpp-omain-pthread当我用gcc-4.6(apt-getinstallg++)编译时,效果很好。程序等了大概十秒,输出了“Helloworld!”#include#include#include#includestd::timed_mutextest_mutex;voidf(){t

c++ - std::random_shuffle 产生相同的结果,即使 srand(time(0)) 被调用一次

在一个函数中,我想生成一个范围内的数字列表:(该函数只会在程序执行时被调用一次。)voidDataSet::finalize(doubletrainPercent,boolgenValidData){srand(time(0));printf("%d\n",rand());//indices={0,1,2,3,4,...,m_train.size()-1}vectorindices(m_train.size());for(size_ti=0;i结果是这样的:850577673246239710241201288231237几秒钟后:856981140246239710241201288

c++ - g++ : can't link with a main executable file

我正在开发一个使用统计攻击来破解wepkey的应用程序。当我用我的makefile编译时(如上)我得到这个错误:ld:can'tlinkwithamainexecutablefile'execStatAttack'forarchitecturex86_64clang:error:linkercommandfailedwithexitcode1(use-vtoseeinvocation)make:*[statAttack]Error1我的项目包含那些文件:statAttack.cpp:包含主要功能,使用上面的文件rc4.h+rc4.cpp:具有那些功能#include#include#i

pygame中time

系统方法pygame.time.get_ticks()pygame.time.wait()pygame.time.delay()pygame.time.set_timer()pygame.time.Clockpygame.time.Clock.tick()pygame.time.Clock.tick_busy_loop()pygame.time.Clock.get_time()pygame.time.Clock.get_rawtime()pygame.time.Clock.get_fps()系统方法pygame.time.get_ticks()功能:(以毫秒为单位)获取时间get_ticks(

c++ - 打印 std::this_thread::get_id() 给出 "thread::id of a non-executing thread"?

这曾经工作得很好(然后外星人一定黑了我的电脑):#include#includeintmain(){std::cout现在它打印thread::idofanon-executingthread。ideone.com打印了一些ID,但有趣的是是什么导致了我平台上的这种行为。$uname-aLinuxxxx3.13.0-77-generic#121-UbuntuSMPWedJan2010:50:42UTC2016x86_64x86_64x86_64GNU/Linux有什么想法吗?编辑:嗯..当我添加std::cout两行打印相同的ID,但是当我删除它时,结果仍然相同-“非执行线程”。

c++ - Boost C++ date_time microsec_clock 和 second_clock

我在BoostC++日期时间库中发现了一个奇怪的结果。microsec_clock和second_clock之间存在不一致,我不明白为什么会这样。我使用的是WindowsXP32位我的代码片段:usingnamespaceboost::posix_time;...ptimenow=second_clock::universal_time();std::cout我期望的打印输出是没有毫秒和毫秒的当前时间。但是,我的电脑中有:2009-10-14T16:07:381970-06-24T20:36:09.375890我不明白为什么我的microsec_clock时间里有一个奇怪的日期(197

c++ - 将 int64_t 转换为 time_duration

我想通过网络传输boost::posix_time::ptime作为boost::int64_t。根据Awaytoturnboost::posix_time::ptimeintoan__int64,我可以很容易地定义我自己的epoch并且仅将time_duration从该引用epoch传输为64位整数。但是如何转换回ptime呢?#include#include#include#includeusingnamespacestd;usingboost::posix_time::ptime;usingboost::posix_time::time_duration;usingboost::