ISO C++11 does not allow conversion from string literal to 'char *'
时间: 2024-05-19 17:11:18 浏览: 11
This error message is related to the C programming language and occurs when you try to assign a string literal (a sequence of characters enclosed in double quotes) to a variable of type `char *` (a pointer to a character).
In C, string literals are stored in read-only memory and attempting to modify them can result in undefined behavior. Therefore, the language specification prohibits assigning a string literal to a `char *` variable, as this could lead to unintended modifications of the original string.
To fix this error, you can declare the variable as a `const char *` instead, which tells the compiler that the pointer is pointing to read-only memory and should not be modified. Alternatively, you can allocate memory dynamically using functions like `malloc()` or `calloc()` and copy the contents of the string literal to the newly allocated memory.
相关推荐
![](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)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)