0

I am copying a smaller array into a larger in this way

int *Arr // this points to array that has size of 7 (i.e) int Arr[7];
int size // this has the size of the above ie. 7

Now I want to make a larger array and copy the previous array data so I do this

int *nArr = new int[size+1];

This is where the problem starts I am trying to copy content using std::copy I am using C++03 so I dont have access to std::begin and std::end

std::copy ( Arr, Arr+size, nArr);

The above statement gives me the error

Error   1   error C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'   c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility 2176
1
  • @tmp: Please state the difference between Arr and &Arr[0], in this case. Commented Mar 22, 2014 at 18:52

2 Answers 2

1

Looks like Microsoft being picky. Just disable the warning; your code is fine.

Sign up to request clarification or add additional context in comments.

Comments

0

Add the preprocessor -D_SCL_SECURE_NO_WARNINGS in your VS project and the above code would compile.

6 Comments

I added D_SCL_SECURE_NO_WARNINGS to the preprocessor definitions but I am still getting the same error
Ideally after adding the MACRO and saving the .sln file and recompiling again should solve your problem.
@Rajeshwar: You forgot a - and a _, and randomly added a space. For no reason. Don't do that.
Looks like my statement std::copy(Arr, Arr+size, nArr); was fine. I just needed to disable the warning
@Rajeshwar: Yes, I said that 43 minutes ago :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.