Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

error C4996: 'strcpy': This function or variable may be unsafe.

$
0
0

Hi !

i'm getting this error while debugging my code:

 error C4996: 'strcpy': This function or variable may be unsafe.

Those are parts of my code :

header file:

#include <iostream>
#ifndef NEWSTRING_H_
#define NEWSTRING_H_

class newstring
{
private:
	char *objekti;
	int hapsira;
	static int numri;
public: 
	newstring(const char *k);
	newstring();
	 ~newstring();
	 friend  std::ostream &operator<<(std::ostream &os, const newstring &n);
};
#endif

c++ file:

...

int newstring::numri=0;
newstring::newstring(const char *k)
{
	hapsira=strlen(k);
	objekti= new char[hapsira+1];
	strcpy(objekti,k);// here is the ERROR line
	numri++;
	std::cout<<numri<<" objekte "<<objekti<<" jane krijuar"<<std::endl;

}

...

There is another warning shown by MS visual c++ runtime library , saying that:

Debug assertion failed!

Expression: (L"Buffer is too small"&&0).

How can i deal with this error? I use VS 2012

Thank you!


Admir


Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>