gpt4 book ai didi

c++ - 稍后在 {} 中添加 unsigned int 数组

转载 作者:行者123 更新时间:2023-11-28 02:45:00 26 4
gpt4 key购买 nike

我可以在 C++ 中做这样的事情吗?或者我应该做什么。

unsigned int code[180];

if ( somethings )
{
code[] = {3150,1550,400,400,400,1150,450,350,400,400,400,1200,400,400,400,1150,400,400,400,400,400,1150,400,1200,400,1200,400,350,400,1200,400,400,400,1150,400,1200,400,1200,400,350,400,400,400,400,400,400,400,1150,400,1200,400,400,400,1150,400,1200,400,400,400,400,400,1150,400,400,400,400,400,1150,450,350,400,400,400,1200,400,1150,400,400,400,1200,400,1150,400,1200,400,1150,450,1150,400,1200,400,350,450,1150,400,400,400,1150,450,350,400,400,400,400,400,400,400,1150,400,400,400,1200,400,400,400,1150,400,1200,400,1150,400,1200,400,1200,400,350,400,400,400,1200,400,400,400,350,400,400,400,400,400,400,400,1150,400,1200,400,400,400,400,400,1150,400,1200,400,1150,450,1150,400,400,350,1200,450,350,400,1200,400,400,400,350,450,350,400,400,400,1200,400,350,450,1150,400,1000};
//irsend.sendRaw(code,sizeof(code)/sizeof(int),khz);
}

最佳答案

我认为您不能在声明后使用 {...} 初始化数组。因此,使用一个临时数组来存储您的内容并将内容 memcpy 到其中(如果这是您的用例)。

unsigned int code[180];
if ( _SOME_CONDITION_ )
{

unsigned int temp1 [] ={3150,1550,400,400,400,1150,450,350,400,400,400,1200,400,400,400,1150,400,400,400,400,400,1150,400,1200,400,1200,400,350,400,1200,400,400,400,1150,400,1200,400,1200,400,350,400,400,400,400,400,400,400,1150,400,1200,400,400,400,1150,400,1200,400,400,400,400,400,1150,400,400,400,400,400,1150,450,350,400,400,400,1200,400,1150,400,400,400,1200,400,1150,400,1200,400,1150,450,1150,400,1200,400,350,450,1150,400,400,400,1150,450,350,400,400,400,400,400,400,400,1150,400,400,400,1200,400,400,400,1150,400,1200,400,1150,400,1200,400,1200,400,350,400,400,400,1200,400,400,400,350,400,400,400,400,400,400,400,1150,400,1200,400,400,400,400,400,1150,400,1200,400,1150,450,1150,400,400,350,1200,450,350,400,1200,400,400,400,350,450,350,400,400,400,1200,400,350,45 0,1150,400,1000};
//irsend.sendRaw(code,sizeof(code)/sizeof(int),khz);

memcpy(code, temp1, sizeof(temp1) / sizeof(*temp1));
} else {
unsigned int temp2 = {...};
memcpy(code, temp2, sizeof(temp2) / sizeof(temp2));
}

关于c++ - 稍后在 {} 中添加 unsigned int 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24715950/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com