11 5 C:\Users\Îâê»Ìì\Desktop\MyCode\Easy_code.cpp [Error] invalid types 'int[int]' for array subscript
时间: 2023-08-17 18:13:16 浏览: 60
这个错误提示是因为你在代码中使用了错误的数组下标类型。在C++中,数组的下标应该是整数类型,而不是数组类型。你需要检查你的代码,并确保在使用数组下标时只使用整数值。
例如,如果你想访问数组中的第n个元素,你应该使用整数n作为下标,而不是另一个数组。
如果你能提供更多的代码片段或上下文,我可以帮助你更具体地解决这个问题。
相关问题
34 16 C:\Users\takyi\Desktop\δÃüÃû1.cpp [Error] cannot pass objects of non-trivially-copyable type 'std::string {aka class std::basic_string<char>}' through '...'
这个错误提示表明在 C++ 代码中,你不能通过 '...'(省略号)语法传递非平凡可复制类型的对象,例如 'std::string'。
在 C++ 中,'...' 是可变参数模板的一部分,用于接收任意数量和类型的参数。然而,对于非平凡可复制类型的对象,编译器无法自动地生成默认的复制构造函数和复制赋值运算符,因此无法正确地处理这些对象。
要解决这个问题,你可以考虑以下几种方法:
1. 使用引用或指针传递对象:将对象作为引用或指针传递给函数,而不是使用 '...'。这样可以避免复制非平凡可复制类型的对象。
2. 使用模板参数:如果你能确定传递的对象的类型,可以将其作为模板参数传递给函数或类模板。这样编译器就能够生成正确的复制构造函数和复制赋值运算符。
3. 重新设计函数接口:如果可能的话,重新设计函数接口以避免需要传递非平凡可复制类型的对象。
请根据你的具体情况选择适合的解决方案,并对代码进行相应的修改。
#include "stm32f10x.h" #include "stdio.h" void USART_init(uint32_t bound) { GPIO_InitTypeDef GPIO_InitStruct; //¶¨ÒåGPIO½á¹¹Ìå±äÁ¿ USART_InitTypeDef USART_InitStruct; //¶¨Òå´®¿Ú½á¹¹Ìå±äÁ¿ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_USART1,ENABLE); //ʹÄÜGPIOCµÄʱÖÓ GPIO_InitStruct.GPIO_Pin=GPIO_Pin_3; //ÅäÖÃTXÒý½Å GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF_PP; //ÅäÖÃPA9Ϊ¸´ÓÃÍÆÍìÊä³ö GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOB,&GPIO_InitStruct); GPIO_InitStruct.GPIO_Pin=GPIO_Pin_4; GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOB,&GPIO_InitStruct); USART_InitStruct.USART_Mode=USART_Mode_Tx|USART_Mode_Rx; USART_InitStruct.USART_Parity=USART_Parity_No; USART_InitStruct.USART_BaudRate=bound; USART_InitStruct.USART_StopBits=USART_StopBits_1; USART_InitStruct.USART_WordLength=USART_WordLength_8b; USART_InitStruct.USART_HardwareFlowControl=USART_HardwareFlowControl_None; USART_Init(USART1,&USART_InitStruct); USART_Cmd(USART1,ENABLE); //ʹÄÜUSART1 } int fputc(int ch,FILE *f) { USART_SendData(USART1,(uint8_t)ch); while(USART_GetFlagStatus(USART1,USART_FLAG_TXE) == RESET); return ch; }
这是一段代码,用于初始化 STM32F10x 的 USART1 模块,实现串口通讯。其中使用了 GPIO_InitTypeDef 结构体和 USART_InitTypeDef 结构体来配置 GPIO 和 USART 的参数,使用了 RCC_APB2PeriphClockCmd 函数来使能 GPIOB 和 USART1 的时钟,使用了 GPIO_Init 和 USART_Init 函数来初始化 GPIO 和 USART,最后使用 USART_Cmd 函数使能 USART1。另外,还有一个 fputc 函数,用于将字符发送到 USART1 的数据寄存器,并等待发送完成。
相关推荐
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)