草庐IT

STL-string

全部标签

c++ - 像迭代器一样编写 STL

我试图学习像迭代器一样编写STL,为此我编写了一个简单的循环数组并在其中添加了一个迭代器。请查看代码底部以查看问题。templateclassRingQueue{T*_marray;int_mbegin;int_msize;public:RingQueue(){_marray=newT[N];_mbegin=0;_msize=0;}voidpush_back(constT&val){if(_msize!=N){_marray[(_mbegin+_msize)%N]=val;_msize++;}elsethrow"QueueFull";}Tpop_front(){if(_msize!=0

c++ - c++ STL迭代器的混淆使用

当我像这样使用迭代器时,//includeheaderfilesusingnamespacestd;intmain(){mapintIntMap;map::iteratorpos;pos=intIntMap.begin();intIntMap[0]=1;intIntMap[3]=5;intIntMap[4]=9;intIntMap[5]=5;//遍历coutfirst"second输出为4;但是当我这样使用迭代器时://includeheaderfileusingnamespacestd;intmain(){mapintIntMap;map::iteratorpos;intIntMap

c++ - std::string 内存泄漏

我有这个类AppController和函数connectPlayer:/*AppController.h*/classAppController{//Someotherdeclarations...private:staticconststringTAG;};/*AppController.cpp*/#include"AppController.h"conststringAppController::TAG="AppController";AppController::AppController(){/*somecodehere...*/}voidAppController::conn

c++ - 我应该使用哪个 STL 容器? C++

我有一个对象“列表”,我想从中随机获取对象并将其推到该列表的前面。只有这种操作才会被执行。所以我不需要快速访问列表的末尾,只需要它的前面和平均访问任何其他地方。哪个容器最适合这个?我在考虑std::vector,但我读到insert操作效率不高。然后我想出了std::deque因为它访问front的速度很快,但是它的eraseatspecificposition方法的效率如何呢?在此先感谢您的帮助。 最佳答案 我们可以为您提供指导,但没有明确的答案——您需要自己进行基准测试,因为这在很大程度上取决于您的收藏和对象大小:对于小对象和/

Java 将 List 转换为 String常见方式

将List转换为String的几种方式使用List的toString()方法将List转换为String;结果前后会带有英文的中括号[],如:[1,2,3,4,5]使用Java8stream流中的Collections.joining()方法,带有逗号分隔符或自定义分隔符将集合转成String字符串使用String.join()方法将带有逗号分隔符或自定义分隔符的集合转换为字符串使用Apachecommons包下的StringUtils.join()方法;转成的String结尾带有分隔符小尾巴,如:"张三,李四,"使用StringBuilder、StringBuffer的append方法自定义

解决日期转换异常 JSON parse error: Cannot deserialize value of type `java.util.Date` from String总结

不积跬步,无以至千里;不积小流,无以成江海-----致奋斗的自己场景:前端向后端传日期参数,后端接收问题,在一次遇到这种低级问题总结一下。文档参考:​​​​​​​SpringFramework中文文档-SpringFramework4.3.21.RELEASEReference|Docs4devSpring是一个开放源代码的设计层面框架,它解决的是业务逻辑层和其他各层的松耦合问题,因此它将面向接口的编程思想贯穿整个系统应用。Spring是于2003年兴起的一个轻量级的Java开发框架,由RodJohnson创建。简单来说,Spring是一个分层的JavaSE/EEfull-stack(一站式)

c++ - visual studio 中涉及 void*、string 和 const char[] 的意外重载解析

我在visualstudio编译器(在VS2010和VS2012中测试)中遇到了以下意外的重载解析行为。最小的例子:#include#includevoidf(void*){std::cout输出:>f(void*)预期输出:>f(conststd::string&)用GCC编译(用4.6.3测试)生成预期的输出。如果我注释掉f()的“conststd::string&”版本,visualstudio会在没有任何警告的情况下愉快地在/W4上编译,而GCC会发出以下错误(如预期的那样):“来自'constvoid的无效转换*'到'void*'[-fpermissive]”。有谁知道为什么

c++ - std::string 和 std::wstring 的前向声明

不能转发声明std::string和std::wstring的问题经常被讨论。据我了解,原因是这些类型是模板类basic_string实例化的类型定义:namespacestd{typedefbasic_stringstring;typedefbasic_stringwstring;}并且该语言不允许typedef的前向声明。使用继承而不是typedef对于c++标准来说不是更好吗:namespacestd{classstring:publicbasic_string{};classwstring:publicbasic_string{};}这样我们就可以转发声明std::string

c++ - boost 中的 path::string() 和 path::generic_string() 有什么区别?

boost::path::string()和boost::path::generic_string()有什么区别,我应该什么时候使用它们? 最佳答案 这在thedocumentation中有明确说明;您只需阅读文档即可获得知识和理解。请从现在开始养成这样做的习惯。boost::路径::字符串在thenativepathnameformat中返回一个std::string.boost::path::generic_string在thegenericpathnameformat中返回一个std::string.何时使用它们中的每一个好吧

c++ - 有没有更优雅的方式在 C++ 中结合 sprintf 和 std::string?

在我的C++代码中,我经常使用以下类型的辅助函数:staticinlinestd::stringstringf(constchar*fmt,...){std::stringret;//Dealwithvarargsva_listargs;va_start(args,fmt);//Resizeourstringbasedontheargumentsret.resize(vsnprintf(0,0,fmt,args));//Endthevarargsandrestartbecausevsnprintfmuckedupourargsva_end(args);va_start(args,fmt