草庐IT

int_void

全部标签

力扣报错runtime error: load of null pointer of type ‘int‘解决思路

记录本算法小白刷力扣的这道题遇到的报错349.两个数组的交集https://leetcode.cn/problems/intersection-of-two-arrays/出现报错的代码 /***Note:Thereturnedarraymustbemalloced,assumecallercallsfree().*/int*intersection(int*nums1,intnums1Size,int*nums2,intnums2Size,int*returnSize){inthash[1000]={0};intresult[1000];//交集是去重的,最多只有1000个数for(inti

c++ - 将 long int 转换为 const time_t

我有变量tmit:longtmit;。我在这段代码中出错:printf("Time:%s",ctime(&tmit));错误说:无法将参数“1”的“longint*”转换为“consttime_t*{akaconstlonglongint*}”到“char*ctime(consttime_t*)”我的问题是,如果我想查看日期,如何在不丢失任何有关时间的信息的情况下将long转换为time_t或如何更改此代码。我正在研究这个answer,但我得到了错误。 最佳答案 一般情况下,您不能这样做,因为std::time_t之间不需要有任何合

从 const int* 到 int* 的 C++ 转换处理意外结果

这个问题在这里已经有了答案:whichpropertyofaconstantmakesitnotchangable?(3个答案)关闭6年前。在c++中,我们知道我们不能将constint*转换成int*。但是我有一个代码片段,我可以在其中将constint*转换为int*。我是C++的初学者,我用谷歌搜索了这个,但我只是得到提到constint*can'tbeconvertedintoint*toavoidconstviolation的链接。我无法弄清楚为什么它编译没有错误#includeusingnamespacestd;intmain(void){constinta1=40;con

c++ - 为什么编译器不断警告我从 `int` 缩小到 `uint8`?

我检查了一遍又一遍,我确定我没有将uint8转换为int隐含在我的代码中,既不向前也不向后。//main.cpp#includeusingstd::cout,std::endl;usinguint8=unsignedchar;structVector{uint8x,y,z;Vectoroperator+(constVector&v)const{returnVector{this->x+v.x,this->y+v.y,this->z+v.z};};voidoperator+=(constVector&);voidoperator-(constVector&)const;Vectorope

c++ - 将 BYTE 数组转换为 unsigned long long int

我正在尝试将BYTE数组转换为等效的unsignedlonglongint值,但我的编码没有按预期工作。请帮助修复它或建议替代方法。额外信息:这4个字节组合成一个十六进制数,输出一个等效的十进制数。假设一个给定的byteArray={0x00,0xa8,0x4f,0x00},十六进制数是00a84f00,它等效的十进制数是11030272。#include#includetypedefunsignedcharBYTE;intmain(intargc,char*argv[]){BYTEbyteArray[4]={0x00,0x08,0x00,0x00};std::stringstr(re

c++ - 将 lambda 传递给 void 指定模板失败

我尽可能地简化了问题,所以这里是有问题的函数:classTest{public:templatevoidExecuteFunction(std::functionf){}};如果我用int类型调用函数,一切正常,但是,如果我用void类型的lambda调用它,它就不再编译了。Testtest;test.ExecuteFunction(//doesn'tcompile[](void)->void{inti=5;});test.ExecuteFunction(//thiscompiles[](int)->void{inti=5;});编译器错误:ErrorC2672'Test::Execu

c++ - c++中int的ostringstream问题

我希望下面的代码输出hello5。相反,它只输出hello。尝试将int输出到ostringstream似乎是个问题。当我将相同的内容直接输出到cout时,我收到了预期的输入。在SnowLeopard上使用XCode3.2。谢谢!#include#include#includeusingnamespacestd;intmain(){intmyint=5;stringmystr="hello";stringfinalstr;ostringstreamoss;oss编辑:请参阅我在下面发布的答案。这似乎是由SnowLeopard上的XCode3.2中的事件配置“调试”中的问题造成的

c++ - 缺少关于 "int main(int argc, char* argv[])"的知识

我是一名物理学家,通常我只想完成计算,这就是我真正需要的。不过我一直在用intmain(intargc,char*argv[])非常令人高兴的是二进制文件在我没想到的级别上变得灵活,即初始化变量~$./program.exeabc(a,bandcarenumbersinthiscase,notlettersok?)所以问题是*如何在不使用文件的情况下以这种方式(或其他方式)“解析”或“传输”事物?*示例:假设“a.exe”给出了一组“X-Y”点(就像在电子表格上一样),我要将其插入“b.exe”。或者说我使用bash/awk脚本来格式化“a.exe”的输出格式,以便在gnuplot上绘

c++ - 为什么在 C++ 中键入 void main() 是不好的

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Differencebetweenvoidmainandintmain?为什么是voidmain(){//returnvoid}不好吗?前几天我输入了这个,有人向我指出这样做是错误的。我很困惑。我这样写已经有一段时间了,我知道它不是C++标准,但编译器不会发出任何警告。为什么这是错误的?

c++ - 如何将 unsigned int 放入 char 数组并将其提取回来

有人可以解释为什么这不起作用吗?我正在尝试将一个unsignedint放入一个char缓冲区,然后将其取回另一个unsignedint。1#include2#include3intmain(){4unsignedinttester=320;5charbuffer[512];6memset(buffer,0,512);7memcpy(buffer,&tester,sizeof(unsignedint));8/*buffer[0]|=tester;9buffer[1]|=(tester>>8);10buffer[2]|=(tester>>16);11buffer[3]|=(tester>>