草庐IT

mm_struct

全部标签

c++ - 解析 yyyy-MM-dd HH :mm:ss date time string?

我有一个来自mysql的日期时间。我需要提取每个部分:intyear;intmonth;intday;inthour;intmin;intsec;例子:2014-06-1020:05:57对于每个组件,是否有比通过stringstream运行它更简单的方法?(请不要使用boost或c++11解决方案)。谢谢 最佳答案 sscanf()可能是最直接的选择。它是一个C库函数,因此纯粹主义者可能不赞成它。这是一个例子:intyear;intmonth;intday;inthour;intmin;intsec;constchar*str="

c++ - 如何使用 make_pair 创建一对 id 和 struct(对象)?

我试图像这样创建一对id和对象:#include#include#includestructnum{doublex;doubley;};intmain(){autotmp=std::make_pair(1,{1.0,2.0});}我收到错误error:nomatchingfunctionforcallto'make_pair(int,)'是否有正确的方法来创建一对id和object? 最佳答案 不,这是你应该如何创建你的对:autotmp=std::make_pair(1,num{1.0,2.0});或者(如@StoryTeller

c++ - struct 专用原子类型如何实现无锁?

我找到了下面的代码,输出总是:std::atomicislockfree?falsestd::atomicislockfree?true这是代码:structA{inta[100];};structB{intx,y;};intmain(){std::coutislockfree?"{}.is_lock_free()islockfree?"{}.is_lock_free()我不明白为什么第二个结构专用原子类型是无锁的而第一个专用原子类型不能是无锁的?提前致谢。 最佳答案 http://en.cppreference.com/w/cpp

c++ - 这是未定义的行为还是 struct init 的错误?

请考虑这段代码:#includeintmain(){structA{intx;inty;intz;intfoo(){std::coutxyzxyzx=1;this->z=10;return2;}};Ab{b.foo(),b.z=b.moo(),3};std::cout我的VS2017(x64版本)中的结果:enterfoo:0,0,0entermoo:5,0,0final:1,2,3ideone.com(gcc6.3)的结果https://ideone.com/OGqvjW):enterfoo:0,0,3entermoo:5,0,3final:1,2,2一个编译器立即将z成员设置为3,

c++ struct没有命名类型

我在头文件中定义一个结构,然后在相应的.cpp文件中设置其成员。为此,我使用了一个函数,该函数应该在其范围内创建一个(相同的)结构,然后返回它。像这样:在标题中:#includeclassGLWindow:publicQGLWidget,publicQGLFunctions{Q_OBJECTpublic:GLWindow(QWidget*parent=0);~GLWindow();//....structDrawable{GLuintvertexBuffer;GLuintindexBuffer;intfaceCount;QMatrix4x4transform;}cube;GLuintc

c++ - .mm 测试文件的 OCMock 3.0.2 链接器错误

我正在使用OCMock3.0.2,我通过cocoapods安装它作为我的测试目标:platform:ios,'7.0'xcodeproj'myProject.xcodeproj'target:myTestTargetdopod'OCMock','~>3.0.2'endlink_with"myTestTarget"在我的测试文件(myTest.mm)中,我包含了OCMock并想尝试新的就地验证策略,如下所示:-(void)test_myTest{MyObject*obj=[MyObjectnew];idrobotMock=OCMPartialMock(obj);[objtestMetho

c++ - struct 旁边的 < > 是做什么的?

好的,下面的代码是从另一个stackoverflow问题中复制过来的heretemplatestructremove_pointer{typedefTtype;};templatestructremove_pointer{typedeftypenameremove_pointer::typetype;};虽然我知道这是模板中的递归定义,但令我困惑的是这些行templatestructremove_pointer这是否意味着remove_pointer将导致T=int*?为什么不T=int**?感谢解释。 最佳答案 这是指针类型的特化

c++ - MSVC : what compiler switches affect the size of structs?

我有两个单独编译的DLL,一个是从VisualStudio2008编译的,一个是从matlab编译的mex文件。两个DLL都包含一个头文件。当我在一个DLL中采用sizeof()结构时,它返回48,而在另一个DLL中它返回64。我检查了/Zp开关,在两个编译中它都设置为/Zp8。还有哪些其他编译器开关可能会影响结构的大小?该结构是一个简单的POCO,没有继承,也没有虚函数。编辑结构看起来像这样:classLIBSPECSGeometry{public:std::vectorm_i;uintN;uintn_im,n_s;};在调试中,sizeof()在两种情况下都返回56,在发行版中,在

c++ - 在 C++ 中更有效地分配 struct 的内存

我正在尝试用C++构造一个结构,如下所示:structkmer_value{uint32_tcount:32;uint32_tpath_length:32;uint8_tacgt_prev:4;uint8_tacgt_next:4;}该结构目前占用12个字节的内存,但我想将大小减小到9个字节。有什么办法可以实现吗?谢谢。 最佳答案 没有可移植的解决方案。对于GCC,这将是struct__attribute__((packed))kmer_value{uint32_tcount:32;uint32_tpath_length:32;ui

c++ - 函数参数中的 struct 关键字和常量正确性

我的库中有一个不透明类型定义为:typedefstructMyOpaqueType*MyType;//easiertotypeforclientcode我不能使用typedef传递指向const结构的指针,所以一些函数看起来像:voidUsePointerToConst(conststructMyOpaqueType*)代替:voidUserPointerToConst(constMyType)//can'tuse,isreallyconstantpointer所以,鉴于此,我有两个问题:参数列表中的struct关键字是否只在C中是必需的?有一个更好的方法吗?我应该创建一个typede