gpt4 book ai didi

c++ - 警告已弃用的从字符串常量到 char * 的转换

转载 作者:搜寻专家 更新时间:2023-10-30 23:59:35 25 4
gpt4 key购买 nike

<分区>

我使用 cmd 编译 .bat 和 g++.exe。有人可以告诉我我做错了什么吗?我正在使用它来练习,因为我遵循有关字符串和数组的教程。请记住,我还在学习。

main.cpp: In function 'int main()':
main.cpp:6:12: warning: deprecated conversion from string constant to 'char*' [-
Wwrite-strings]
main.cpp:10:12: warning: deprecated conversion from string constant to 'char*' [
-Wwrite-strings]
main.cpp:11:12: warning: deprecated conversion from string constant to 'char*' [
-Wwrite-strings]
Press any key to continue . . .

我的代码:

      using namespace std;
#include <iostream>

int main() {
//Asterisk to make the variable an array. Takes 8 bytes of memory (8 characters including spaces).
char *a = "hi there";
//Inside square brackets is the number of bytes of memory to use. More consumtion of resources
char b[500]="hi there";
//For a new line, type \n. For a tab, type \t.
char *c = "Hi There\nFriends!";
char *d = "\t\tHi There Friends!";
//endl will end the line.
cout << a;
cout << b << endl;
cout << c << endl;
cout << d << endl;
}

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