草庐IT

STD_LOGIC

全部标签

c++ - 从 char* 初始化 std::string 而不复制

我遇到这样一种情况,我需要处理大量(许多GB)数据:通过附加许多较小的(Cchar*)字符串构建一个大字符串修剪字符串将字符串转换为C++conststd::string进行处理(只读)重复每次迭代中的数据都是独立的。我的问题是,我想尽量减少(如果可能的话消除)堆分配的内存使用量,因为目前这是我最大的性能问题。有没有一种方法可以将C字符串(char*)转换为STLC++字符串(std::string)而无需std::string在内部分配/复制数据?或者,我可以使用stringstreams或类似的东西来重新使用大缓冲区吗?编辑:感谢您的回答,为了清楚起见,我认为修改后的问题是:如何有

c++ - std::runtime_error::what() 在使用嵌套异常时导致访问冲突

我不是在寻找解决这个问题的方法,只是想了解它的原因。一位同事向我展示了一些代码,这些代码在由VisualStudio2008编译以在WindowsMobile6ARMV4I下运行时会导致访问冲突。同样的代码在x86Windows下运行良好,他声称它在GCC编译的Linux下运行(我尚未验证)。我将问题归结为以下代码:intmain(intargc,char*argv[]){try{throwstd::runtime_error("a");}catch(std::runtime_error&e1){try{try{throwstd::runtime_error("b");}catch(s

c++ - 用于快速 std::wstring 分配的自定义分配器

是否有任何开源分配器(可能在Boost中)可以与std::wstring一起使用,实现快速分配模式,如thisblogpost中所示?Boost.Pooldoesn'tseemwellsuitedforthispurpose. 最佳答案 不,没有(我搜索了几个小时,一次)。如果您不关心在使用过程中释放内存,那么您自己做起来相当简单。如果要动态释放,那么freelist管理、LRU等工作就变得很多了。 关于c++-用于快速std::wstring分配的自定义分配器,我们在StackOver

c++ - 从字符串到数字大于 std::numeric_limit<double>::digits10 的 double 的转换

std::stringstr="12345679012.124678";doubleback=boost::lexical_cast(str);std::stringstr2=boost::lexical_cast(back);//herestr2isequaltostr即使数字的有效数字大于std::numeric_limit::digits10(即15),此处也没有丢失(即最终字符串=原始字符串)是否正常? 最佳答案 是的,这很正常。std::numeric_limit::digits10指的是确保强制转换无损的最大位数。这并不

c++ - 编译器如何传递 `std::initializer_list` 值? (或 : how can I get around a universal overload with one? )

Continuingmysaga,我意识到我可以使用单个std::initializer_list参数来重载我的访问函数:classarray_md{//...my_type&operator[](size_typei){/*Lotsofcode*/}my_typeconst&operator[](size_typei)const{/*sameLotsofcode,with"const"sprinkledin*/}my_type&operator[](std::initializer_listi){/*Lotsofdifferentcode*/}my_typeconst&operato

c++ - 我们应该在何时、何地以及为什么使用 "BigObject&& rv = std::move(big_obj);"?

我的编译器是最新的VC++2013预览版。#includestructBigObject{...};voidf(BigObject&&){}voidf(BigObject&){}voidf(BigObject){}intmain(){BigObjectbig_obj;BigObject&r1=big_obj;//OK.BigObject&&r2=big_obj;//errorC2440BigObject&&r3=std::move(big_obj);//OK.BigObject&&r4=r3;//errorC2440f(r3);//errorC2668:'f':ambiguouscal

c++ - to_string 不是 std 的成员,g++ (mingw)

我正在制作一个小型词汇内存程序,其中会随机闪现单词以了解含义。正如BjarneStroustroup告诉我们的那样,我想使用标准C++库,但我一开始就遇到了一个看似奇怪的问题。我想将一个long整数更改为std::string以便能够将其存储在文件中。为此,我使用了to_string()。问题是,当我用g++(版本4.7.0,如其--‍version标志中所述)编译它时,它说:PSC:\Users\Anurag\SkyDrive\College\Programs>g++-std=c++0xttd.cppttd.cpp:Infunction'intmain()':ttd.cpp:11:2

c++ - 将 boost::bimap 转换为 std::map

将bimap转换为std::map的明显方法似乎不起作用。下面是正确/好的转换方法吗?有更好/更短的方法吗?typedefboost::bimapMapType;MapType_bimap;//Fill_bimapMapType::left_map&lmap=_bimap.left;//std::mapbmap(lmap.begin(),lmap.end());//THISDOESNTWORKstd::mapbmap;BOOST_FOREACH(MapType::left_const_referenceentry,lmap){bmap[entry.first]=entry.second

c++ - std::map 是否要求比较器的 operator() 为常量?

在OSX10.8上使用libc++时,以下代码无法使用XCode4.5的clang++进行编译:#include#includeclassFoo{public:explicitFoo(intval_):val(val_){}intval;};structFooComparator{booloperator()(constFoo&left,constFoo&right){returnleft.valm;Foof(4);m[f]=std::string("four");return0;}错误:broken.cpp:11:8:note:candidatefunctionnotviable:'

c++ - win32 std::thread 是否泄漏内存?

我在Windows732位下使用MinGWgcc4.8.2编译了以下代码://t.cpp#include#includeclassMine{public:Mine(){std::cout使用g++t.cpp-std=c++11-static-ggdb,并使用Dr.Memory和drmemorya.exe进行调试,我得到了以下输出:Dr.Memoryversion1.6.1739build42builtonFeb23201422:29:25Dr.Memoryresultsforpid7400:"a.exe"Applicationcmdline:"a.exe"Recorded102supp