Ignoring negative values in array

I need to ignore negative values in an array, but not exit the function.
For example if the user enters:
1,2,3,4,-1,-2,0
the array would be
[1,2,3,4]
Is there a way to ignore these values??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>

std::size_t read_positive( int* array, std::size_t n )
{
    std::size_t pos = 0 ;

    int value ;
    while( pos < n )
    {
        if( std::cout << "value? " && std::cin >> value ) // if a number was read
        {
            if( value >= 0 ) array[pos++] = value ; // if not negative
            else std::cerr << "negative value was ignored\n" ;
        }

        else break ; // input failed
    }

    return pos ; // number of values entered
}

int main()
{
    constexpr std::size_t N = 100 ;
    int array[N] = {0} ;

    const std::size_t nvalues = read_positive( array, N ) ;

    for( std::size_t i = 0 ; i < nvalues ; ++i ) std::cout << array[i] << ' ' ;
    std::cout << '\n' ;
}

http://rextester.com/UDCH29167
Topic archived. No new replies allowed.