title: What is the best way to convert unsigned integers to their octal representations and vice versa in C++?
body: <p>Currently I'm using <code>while</code> loops:</p>
  
  <pre><code>std::string to_octal(unsigned int num)
  {
      int place = 1, remainder, octal = 0;
      while (num != 0)
      {
          remainder = num % 8;
          decimal /= 8;
          octal += remainder * place;
          place *= 10;
      }
      return std::to_string(octal);
  }
  
  unsigned int to_num(std::string octal)
  {
      unsigned int octal_n = std::stoi(octal);
      int place = 1, remainder, num = 0;
      while (num != 0)
      {
          remainder = octal_n % 10;
          octal_n /= 10;
          num += remainder * place;
          place *= 8;
      }
      return num;
  }
  </code></pre>
  
  <p>Which seems inefficient. Is there a better way to do this?</p>