草庐IT

seg_length

全部标签

c++ - std::string 的 strlen(str.c_str()) 和 str.length() 之间的区别

作为一种隐含的理解,我一直认为std::string的每一个实现必然必须满足strlen(str.c_str())==str.length()对于每个字符串str。C++标准对此有何规定?(是吗?)背景:至少VisualC++和gcc附带的实现没有这个属性。考虑这个例子(参见hereforaliveexample)://Output://stringsaysitslengthis:13//strlensays:5#include#include#includeintmain(){std::stringstr="Hello,world!";str[5]=0;std::cout当然,没有注

c# - 为什么 Array.Length 是一个 int,而不是一个 uint

这个问题在这里已经有了答案:Whydoes.NETuseintinsteadofuintincertainclasses?(7个答案)关闭9年前。为什么Array.Length是int,而不是uint。这让我很困扰(有点),因为长度值永远不会是负数。这也迫使我在自己的类中使用int作为长度属性,因为当你指定一个int值,这需要显式转换...所以最终的问题是:unsignedint(uint)有什么用吗?甚至微软似乎也不使用它们。

c++ - STL String::length() 段错误

#include#include#include/*UsingSTL'sstringclassbecausetheproblemdoesnotreferanylimitsregardingthenumberofcharactersperline.*/usingnamespacestd;intmain(){stringline;vectorlines;while(getline(cin,line)){lines.push_back(line);}unsignedinti,u;unsignedintopening=1;//2iflastwasopening,1ifitwasclosingf

c++ - 错误 : Variable length array of Non-POD element type 'string'

在开始之前,我必须首先声明,我已经研究过针对此错误的可能解决方案。不幸的是,它们都与不使用数组有关,这是我项目的要求。另外,我目前正在学习CS入门类(class),所以我的经验几乎没有。数组的用途是从文件中收集名称。因此,为了初始化数组,我计算了名称的数量并将其用作大小。问题是标题中所述的错误,但我仍然使用一维数组时看不到解决方法。主要.cpp#include#include#include#include#include#include"HomeworkGradeAnalysis.h"usingnamespacestd;intmain(){ifstreaminfile;ofstrea

从函数访问全局指针时的seg故障错误

为什么当我将值分配给函数中的指针时会发生分割故障。source_1.cint*p=NULL;func(int**y){*y=(int*)malloc(sizeof(int));*y=1;}intmain(){func(&p);printf("%d\n",*p);}source_2.cint*p=NULL;func(int**y){*y=(int*)malloc(sizeof(int));*y=1;}intmain(){int*t=p;func(&t);printf("%d\n",*t);}指针定义和通过地址有什么问题?看答案简而言之,您可以通过使用编译器警告标志来找出指针操作中的问题。在Win

c++ - 在抛出 'std::length_error' 实例后调用终止

这是我在这里的第一篇文章。由于我是新手,这个问题可能很愚蠢。当显示以下错误消息时,我正在编写一段代码,在抛出“std::length_error”的实例后调用终止什么():basic_string::_S_create/home/gcj/finals/home/gcj/quals中止的地方以下是有问题的代码,尤其是第39行到第52行。这对我来说很奇怪,因为这段代码几乎与第64行到第79行相同。intmain(){std::vectordirs,need;std::stringtmp_str;std::ifstreamfp_in("small.in");std::ofstreamfp_o

当我尝试从故事板中脱颖而出时,为什么我会在这条代码中遇到SEG错误?

因此,我试图将故事板中的按钮键入另一个ViewController。但是,每次点击按钮时,应用都会崩溃。这是应用程序崩溃时突出显示的代码行。overridefuncprepare(forsegue:UIStoryboardSegue,sender:Any?){letbarcodeViewController:BarcodeReaderViewController=segue.destinationas!BarcodeReaderViewControllerbarcodeViewController.delegate=self}这是我的barcodevcimportUIKitimportAVFo

iphone - NSString "initWithBytesNoCopy:length:encoding:freeWhenDone:"可以修改输入 "bytes"吗?

-(id)initWithBytesNoCopy:(void*)byteslength:(NSUInteger)lengthencoding:(NSStringEncoding)encodingfreeWhenDone:(BOOL)flag"bytes"不是常量指针。这是否意味着该方法可能会修改“字节”? 最佳答案 您应该假设它可能会发生变异,因为那是签名并且没有其他文件可以否定它。所以我的回答是:这是因为SEL的签名不会/不能为NSMutableString更改它被声明为非常量。这里有一些NSString创建替代方案,它们建议在没

Netty数据粘包问题:解决Adjusted frame length exceeds大数据异常

Netty数据粘包问题:解决Adjustedframelengthexceeds大数据异常概述:在网络通信中,数据的传输往往是以数据包(Packet)为单位进行的。而在使用Netty进行网络编程时,由于网络传输的不确定性,可能会出现数据粘包(Packet粘连)的问题。本文将重点讨论Netty中遇到的一种粘包问题:"Adjustedframelengthexceeds大数据"异常,并提出解决方案。一、问题描述:当在Netty应用程序中,接收到一个超过预期长度的数据包时,可能会抛出"TooLongFrameException:Adjustedframelengthexceeds大数据"异常。这种异

已解决java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0 异常的正确解决方法,亲测有效!!!

已解决java.lang.ArrayIndexOutOfBoundsException:Index0outofboundsforlength0异常的正确解决方法,亲测有效!!!文章目录报错问题解决思路解决方法交流报错问题java.lang.ArrayIndexOutOfBoundsException:Index0outofboundsforlength0解决思路这个错误通常是由于访问了一个空数组或者超出了数组长度范围导致的。下滑查看解决方法解决方法要解决这个问题,你可以按照以下几个步骤进行:检查数组是否为空:在访问数组之前,确保数组已经被正确初始化并且不是空的。你可以使用array.lengt