getting continuous ranges from sorted integer vector in c++
===

extracting continuous ranges from a integer vector

I have sorted vector(with non-repeated values) like this [1,2,3,6,7,8,12,15]

I need to extract every range from such vector like 1-3,6-8,12-15 in to a string like:

**"0-3,6-8,12,15"**

Approach I was thinking of:

1) running a loop from from first member and matching next element with an increment .. 2) keep going till you get a match.. 3) when a mismatch occurs insert first match to last match into string. 4) wait for next match and carry on till end of string.