c – 相当于Delphi的STL容器集?
发布时间:2020-12-16 09:57:41 所属栏目:百科 来源:网络整理
导读:是否存在功能类似于Delphi“set”的STL容器,以下代码取自DelphiBasics: type TDigits = set of '1'..'9'; // Set of numeric digit charactersvar digits : TDigits; // Set variable myChar : char;begin digits := ['2','4'..'7']; // Now we can test to
是否存在功能类似于Delphi“set”的STL容器,以下代码取自DelphiBasics:
type TDigits = set of '1'..'9'; // Set of numeric digit characters var digits : TDigits; // Set variable myChar : char; begin digits := ['2','4'..'7']; // Now we can test to see what we have set on: for myChar := '1' to '9' do begin if (myChar In digits) then DoSomething() else DoSomethingElse(); end; end; 解决方法
与Delphi的集合最接近的是< bitset>中的STL std :: bitset容器.头.
相似点: >您可以在开始时设置其范围; 区别: >在Delphi中,集合的最大大小为256位,因此如果要创建更大的集合,则必须使用类似字节集的数组[1..N].在C中,std :: bitset没有这个限制;>在Delphi中,按值包含/排除设置位.在C中,std :: bitset位由索引设置/重置. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |