przesunięcie tablicy bez pierwszego elementu

0

Hej jestem zupełnie nowy w C++, nie karcie za złożoność tego pytania.
Chiałbym przesunąć tablicę o 1 w lewo bez elementu z indeksem 0.
int table[8] = { 1,2,3,4,5 };
for (int i = 0; i < 4; ++i) {
table[++i] = table[i + 1];
cout << table[i] << " ";
}
Input: 1,2,3,4,5
Output 1,3,4,5

1

Masz już w bibliotece standardowej std::rotate.

#include <algorithm>
#include <iterator>
#include <iostream>

int main() {
    int array[] = {1, 2, 3, 4, 5, 6};
    std::rotate(std::begin(array), std::begin(array) + 1, std::end(array));
    std::copy(std::begin(array), std::end(array), std::ostream_iterator<int>(std::cout, " "));
}
0
for(int i=2;i<sizeof(table)/sizeof(*table);++i) table[i-1]=table[i];
for(int i=1;i<sizeof(table)/sizeof(*table);++i)  cout< table[i-1]<<" ";

1 użytkowników online, w tym zalogowanych: 0, gości: 1