草庐IT

char_set

全部标签

c++ - C++ 中的 "set"是什么?它们什么时候有用?

我很难概念化C++集,实际上是一般集。它们是什么?它们有什么用? 最佳答案 如果您在一般情况下理解集合有困难,请不要难过。大部分数学学位都花在了与集合论的相处上:http://en.wikipedia.org/wiki/Set_theory将集合视为唯一的、无序的对象的集合。在很多方面它看起来像一个列表:{1,2,3,4}但顺序并不重要:{4,3,2,1}={1,2,3,4}并忽略重复:{1,1,2,3,4}={1,2,3,4}C++集是此数学对象的实现,具有内部排序的奇怪功能。但这只是实现的细节,与理解数据结构无关。排序只是为了速

c++ - 将 const char * 转换为 std::string

这个问题在这里已经有了答案:Howtoconvertaconstchar*tostd::string[duplicate](6个答案)关闭8年前。我有一个从处理函数返回的constchar*,我想将它转换/分配给std::string的实例进一步操纵。这看起来应该是直截了当的,但我找不到任何说明应该如何完成的文档。显然,我错过了一些东西。见解赞赏。

c++ - g++ 将返回的字符串文字视为 const char 指针而不是 const char 数组

当从应该使用g++(版本4.7.3)执行隐式转换的函数返回字符串文字时,我看到了一些奇怪的行为。任何人都可以解释为什么以下代码:#includeclassTest{public:templateTest(constchar(&foo)[N]){printf("Templateconstchararrayconstructor\n");}Test(char*foo){printf("char*constructor\n");}};Testfn(){return"foo";}intmain(){Testt("bar");Testu=fn();return0;}产生结果:Templateco

c++ - 我不明白在下面的代码中将 char buffer[] 与 X 类型的对象对齐的原因

Stroustrup在他的新书第151页中展示了以下使用类型说明符alignas的示例:Sometimes,wehavetousealignmentinadeclaration,whereanexpression,suchasalignof(x+y)isnotallowed.Instead,wecanusethetypespecifieralignas:alignas(T)means"alignjustlikeaT."Forexample,wecansetasideuninitializedstorageforsometypeXlikethis:voiduser(constvector

c++ - 使用 Swig 将 std::set 转换为 ruby

我正在使用Swig在ruby​​中使用C++,目前我已经完成了文件david.h的简单示例#includeclassDavid{public:David(intx){this->x=x;}voidannounce(){printf("David%d\n",x);}intx;};还有一个像这样的swig文件%module"david"%{#include%}classDavid{public:David(intx);voidannounce();intx;};我的extconf.rb看起来像这样require'mkmf'system('swig-c++-rubylibdavid.i')o

c++ - 从 *char 数组转换时有哪些严格的别名规则?

在将char数组转换为其他类型时,我对严格的别名规则感到困惑。我知道允许将任何对象转换为char数组,但我不确定反过来会发生什么。看看这个:#includeusingnamespacestd;struct{alignas(int)charbuf[sizeof(int)];//correct?}buf1;alignas(int)charbuf2[sizeof(int)];//incorrect?struct{floatf;//obviouslyincorrect}buf3;typenamestd::aligned_storage::typebuf4;//obviouslycorrecti

c# - 如何将带有 const char* 的 C union 映射到 C# 结构?

在本地库的回调函数中,我需要访问一个espeak_EVENT数组。问题出在原C代码中的UNION语句:typedefstruct{espeak_EVENT_TYPEtype;unsignedintunique_identifier;//messageidentifier(or0forkeyorcharacter)inttext_position;//thenumberofcharactersfromthestartofthetextintlength;//wordlength,incharacters(forespeakEVENT_WORD)intaudio_position;//th

Starting MySQL. mysqld_safe error: log-error set to ‘/var/log/mariadb/mariadb.log‘,however file don‘

@[TOC](Mysql启动报错并成功解决:StartingMySQL.2023-11-16T06:24:39.857506Zmysqld_safeerror:log-errorsetto‘/var/log/mariadb/mariadb.log’,howeverfiledon’texists.Createwritableforuser‘mysql’.TheserverquitwithoutupdatingPIDfile(/var/lib/mysql/y[FAILED]d))当我们启动MySQL数据库时,一直报错。。。。。。。。。。。。在网上找了很多种方法都无法解决,终于…皇天不负有心人,终于

c++ - std::unordered_(set|map) 基于范围的删除的真实用例是什么?

发现std::unordered_set和std::unordered_map具有基于范围的erase(first,last)这在我看来是另一种射自己腿的好方法。也许有人知道此类功能的实际用例?或者这可能被认为是糟糕的设计? 最佳答案 我认为是为了提供与常规map和set的兼容性。但原则上我还是觉得有用。如果某个范围的值已停用,您希望将它们从集合中移除。但是正常的用例是查找(比插入/删除常见一百万倍)并且不遍历,所以无序版本很好。它怎么能射你?这与循环删除每个没有什么不同。啊,简单的开始,结束范围正向遍历是行不通的,所以你认为提供的

c++ - std::set<K, C>::operator<(const std::set<K, C>&) 不使用 C() 但 std::less()

无法删除我自己的问题,所以改写它... 最佳答案 这实际上不是实现中的错误,尽管它可以说是标准中的错误:23.2.1Generalcontainerrequirements[container.requirements.general]13Table98listsoperationsthatareprovidedforsometypesofcontainersbutnotothers.Thosecontainersforwhichthelistedoperationsareprovidedshallimplementtheseman