Нужна помощь, пишу код в VS C++. Выдает ошибку C4996. Раньше прекрасно работала функция strcpy, сейчас же требуют strcpy_s. Если что, я новичок
#include <iostream>
class MyString
{
private:
char* Buffer;
public:
MyString(const char* InitialInput)
{
if (InitialInput != NULL)
{
Buffer = new char[strlen(InitialInput) + 1];
strcpy(Buffer, InitialInput);
}
else
{
Buffer = NULL;
}
}
~MyString()
{
std::cout << "Invoking destructor, clearing up" << std::endl;
if (Buffer != NULL)
{
delete [] Buffer;
}
}
int GetLength()
{
return strlen(Buffer);
}
const char* GetString()
{
return Buffer;
}
};
int main()
{
MyString SayHello("Hello from String Class");
std::cout << "String buffer in MyString is " << SayHello.GetLength();
std::cout << " characters long" << std::endl;
std::cout << "Buffer contains: " << SayHello.GetString() << std::endl;
return 0;
}
Ответы (1 шт):
Автор решения: Harry
→ Ссылка
Ну вам же четко сказали, что делать!
Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
Вариант первый —
Buffer = new char[strlen(InitialInput) + 1];
strcpy_s(Buffer, strlen(InitialInput)+1, InitialInput);
}
Вариант второй —
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
Что именно вам было непонятно в сообщении об ошибке?