我根据书上给出的语法和例子敲出的这串代码,在vs2022上出现编译错误,但在dev c++上就可以运行,请问这是为什么?
下面给出代码
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int n;
char *array1 = "Happy Birthday to You";
char array3[15];
char array2[25];
strcpy(array2, array1); //复制array1到array2
cout << "The string in array1 is :" << array1
<< "\nThe string in array2 is :" << array2 << endl;
/*
strcpy(array3,array1); //复制array1到array3
cout<<array3<<endl;
*/
n = sizeof(array3);
strncpy(array3, array1, n - 1);
array3[n - 1] = '\0';
cout << "The string in array3 is: " << array3 << endl;
return 0;
}