Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8424509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:00:45+00:00 2026-06-10T04:00:45+00:00

int *arr = (int*) malloc(100*sizeof(int)); int *arr_copy = (int*) malloc(100*sizeof(int)); srand(123456789L); for( int i

  • 0
int *arr = (int*) malloc(100*sizeof(int));
int *arr_copy = (int*) malloc(100*sizeof(int));
srand(123456789L);
for( int i = 0; i < 100; i++) {
    arr[i] = rand();
    arr_copy[i] = arr[i];
}

// ------ do stuff with arr ------

// reset arr...
std::copy(arr_copy, arr_copy+100,  arr);

while compiling this I get this warning for std::copy():

c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2227):
warning 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'

I know how to disable/ignore the warning, but is there is a simple one liner solution to make a “checked iterator” out of an unchecked pointer? Something like (I know cout is not an unchecked pointer like int*, but just e.g.):

ostream_iterator<int>  out(cout," ");

std::copy(arr_copy, arr_copy+numElements,  out);

I don’t want to write a whole new specialized class my_int_arr_output_iterator : iterator.... But can I use one of the existing iterators?

—edit—

As there are many many questions abt my usage of c-style-arrays and malloc instead of STL containers, let me just say that I’m writing a small program to test different sorting algorithms’ performance and memory usage. The code snippet you see above is a specialized (original code is template class with multiple methods, testing one algorithm for different number of elements in arrays of different types) version specific to the problem.

In other words, I do know how to do this using STL containers (vector) and their iterators (vector::begin/end). What I didn’t know is what I asked.

Thanks though, hopefully someone else would benefit from the answers if not me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:00:47+00:00Added an answer on June 10, 2026 at 4:00 am

    The direct answer you’re looking for is the stdext::checked_array_iterator. This can be used to wrap a pointer and it’s length into a MSVC checked_iterator.

    std::copy(arr_copy, arr_copy+100, stdext::checked_array_iterator<int*>(arr, 100) );

    They also provide a stdext::checked_iterator which can wrap a non-checked container.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: #include <stdlib.h> #include <stdio.h> #define SIZE 100 int* arr;
#include<stdio.h> int max = 100; int main() { int a,j; int * arr =
int arr[ 5 ] = { 0 }; int i = 8; // out
int main() { int p; scanf(%d,&p); fun() { int arr[p]; // isn't this similar
I don't understand the output of this program: int arr[]={1,7,4,2,5,8}; int x=(&(arr[arr[1]-arr[4]])-arr); printf(%d ,x);
This is the usual way for declare a Java array: int[] arr = new
why doesn't the element get swapped public static void SwapArray(int[,] arr) { for (int
I declared a multidimensional array in C, like so: int arr[4][2]; int length =
Is there a better shorter way than iterating over the array? int[] arr =
I have the following piece of code in C++. int arr[] = {1, 2,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.