这是啥情况dev能运行vs就报错

img


#include <iostream>
#include <string.h>
using namespace std;
class Array
{
private:
    char s[100];
    char a[100];
public:
    //构造函数3:数据成员是字符数组,字符串拷贝函数
    Array(char t[], char d[])
    {
        strcpy(s, t);
        strcpy(a, d);
    }
    void show()
    {
        cout << s << endl;
        cout << a << endl;
    }
    void pinjie()
    {
        char* p = s + strlen(s);
        char* q = a + 0;
        while (*q != '\0')
        {
            *p = *q;
            p++;
            q++;
        }
        *q = '\0';

    }

};
int main()
{
    char m[100] = { "apple" };
    char n[100] = { "tree" };
    Array p(m, n);
    p.show();
    p.pinjie();
    p.show();
    return 0;
}

在VS里面把strcpy()函数写成strcpy_s()应该就行了。之前学C语言的时候我遇到过这个,VS里面用scanf ()的时候也是要写成scanf _s()才行,这是VS的一种保护代码机制。可能这也是学校推荐用DEV的原因的,DEV用着方便,但是没有VS用着有感觉🤓