C++: Decimal to Octal

One way to convert a decimal number to octal in C++ is by using a loop to repeatedly divide the decimal number by 8 and store the remainder. The octal number can then be formed by reversing the order of the remainders.

Here's the code:

```
#include <iostream>
#include <vector>
using namespace std;

int main() {
int decimal, quotient, remainder;
vector<int> octal;

cout << "Enter a decimal number: ";
cin >> decimal;

quotient = decimal;

while (quotient != 0) {
remainder = quotient % 8;
octal.push_back(remainder);
quotient /= 8;
}

cout << "The octal equivalent is: ";
for (int i = octal.size() - 1; i >= 0; i--) {
cout << octal[i];
}

return 0;
}
```

In this code, we first prompt the user to enter a decimal number. Then we declare three integer variables: `decimal` to store the input number, `quotient` to represent the integer division result, and `remainder` to store the remainder of the division.

We also declare a `vector<int>` named `octal` where we'll store the remainders in reverse order.

The `while` loop performs the division and stores the remainder in the `octal` vector. The loop continues until the `quotient` becomes zero.

Finally, we display the octal equivalent by iterating through the `octal` vector in reverse order and displaying each element.

For example, if the user enters `79`, the program will output `The octal equivalent is: 117`.