草庐IT

Union-Find

全部标签

c++ - std::string::find 在 C++ 中无法正常工作

我正在尝试验证特定字符串是否在输入字符串中,如果是,则根据找到的字符串执行某些操作;但似乎无论如何它总是在做第一个任务......if(inputString.find(str1)>=0){//dosomething}elseif(inputString.find(str2)>=0){//dosomethingelse}else{std::cout无论inputString中是否存在str1,它总是进入//dosomethingblock。如果我这样做intstr1pos=inputString.find(str1);intstr2pos=inputString.find(str2);

c++ - 带有构造函数的类的匿名 union/结构

即使我使用-std=c++11标志编译,GCC也会提示这段代码,而且我的gcc版本应该支持无限制union(>4.6)。union{struct{float4I,J,K,T;};struct{float4m_lines[4];};struct{floatm16f[16];};struct{floatm44f[4][4];};};请注意,float4有一个带0个参数的非默认构造函数。classfloat4{public:float4();....};知道我能做什么吗?错误是:::::I’withconstructornotallowedinanonymousaggregate

c++ - 包含可变结构的 union

这似乎类似于PODstructscontainingconstantmember,但有点相反。#includestructA{inta;};unionU{volatileAa;longb;};intmain(){Uu1;Uu2;u1.a.a=12;u2=u1;std::coutg++4.8.3编译这段代码没有错误并且运行正常:$g++-std=c++03a.cpp-oa_gcc$./a_gcc12但是clang++3.5.1产生了一个错误(我手动包装了错误消息以防止代码框滚动):$clang++-std=c++03a.cpp-oa_clanga.cpp:8:7:error:member

c++ - 将 union 与结构内的位字段结合使用的正确语法

我有以下一系列结构。structFooWord1{unsignedintFill:8;unsignedintsomeData1:18;unsignedintsomeData2:6;};structFooWord2{unsignedintFill:8;union{unsignedintA_Bit:1;unsignedintB_Bit:1;};unsignedintsomeData3:23;};structFoo_Data{FooWord1fooWord1;FooWord2fooWord2;FooWord3fooWord3;//similartoFooWord1FooWord4fooWor

c# - C# 中的 C++ union — 奇怪的行为

我正在尝试使用C#中的VHDAPI创建一些vhd/vhdx文件。有一个看起来像这样的C++union:typedefstruct_CREATE_VIRTUAL_DISK_PARAMETERS{CREATE_VIRTUAL_DISK_VERSIONVersion;union{struct{GUIDUniqueId;ULONGLONGMaximumSize;ULONGBlockSizeInBytes;ULONGSectorSizeInBytes;PCWSTRParentPath;PCWSTRSourcePath;}Version1;struct{GUIDUniqueId;ULONGLONG

c++ - Clangs C++ 模块 TS 支持 : How to tell clang++ where to find the module file?

在他的talk在CppCon上,RichardSmith提到尽管ModuleTS支持目前正在进行中,但它已经可以使用了。所以我从svn构建了clang4.0,并在一个非常简单的示例上进行了尝试。在我的myclass.cppm文件中,我为int定义了一个简单的包装器modulemyclass;exportclassMyClass{public:MyClass(inti):_i{i}{}intget(){return_i;}private:int_i;};和我的main.cpp只是创建该类的一个实例,并将其保存的int输出到std::cout。#include#includeimportm

c++ - 性能 std::strstr 与 std::string::find

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:C++string::findcomplexity最近我注意到函数std::string::find比函数std::strstr慢一个数量级-在我的GCC4.7环境中在Linux上。性能差异取决于字符串的长度和硬件架构。差异的原因似乎很简单:std::string::find基本上在循环中调用std::memcmp-具有时间复杂度O(m*n)。相比之下,std::strstr针对硬件架构进行了高度优化(例如使用SSE指令)并使用更复杂的字符串匹配算法(显然是Knuth-Morris-Pratt)。我也很惊讶没

c# - FlatBuffers:使用 union 发送多种数据包类型

我将通过连接发送多种缓冲区类型。为简单起见,想象一个类似这样的模式:namespaceMyEvents;tableEventOne{id:uint;timestamp:ulong;adress:string;}tableEventTwo{id:uint;timestamp:ulong;strength:float;}unionEvents{EventOne,EventTwo}tableEventHolder{theEvent:Events;}root_typeEventHolder;我为C++和C#生成所需的文件,并根据需要将它们包含在我各自的项目中。下面是我在C++中编码事件的方式-

c++ - 找不到 boost_process cmake find_package

我正在尝试将boost库导入我的C++项目,但出于某种原因它找不到Boost.Process,尽管它找到了其他库。我的CMakeLists.txt文件:cmake_minimum_required(VERSION3.9FATAL_ERROR)set(PROJECT_NAME"test-stuff"CXX)project(${PROJECT_NAME})set(Boost_USE_MULTITHREADEDON)find_package(Boost1.64.0REQUIREDsystemfilesystemprocess)if(Boost_FOUND)include_directorie

c++ - 匿名空无标记类、结构、 union 和枚举

!免责声明!:请注意,我说的是未标记声明。我知道这可能是一个非正式术语,我的意思是声明不是typedef并且它不声明匿名类型的对象。在这些情况下,一切都很清楚。问题一:以下哪个是格式正确的C++程序?(多选)//Oneintmain(){struct{};//orclass{};shouldbethesame}//Twointmain(){enum{};}//Threeintmain(){union{};}备注:MSVC9.0接受所有这三个。在第一位,它给出了警告。在第二和第三,我们得到0个错误和0个警告。在线comeau仅接受三号,一号和二号无法编译,并显示诊断消息“声明未声明任何内