Convert Decimal Number to Octal String using C++

std::ostringstream class

#include <iostream>
#include <sstream>

int main()
{
    int decimalNumber = 40;

    std::ostringstream oss;
    oss << std::oct << decimalNumber;
    std::string octalString = oss.str();

    std::cout << octalString << std::endl;

    return 0;
}

Leave a Comment

Cancel reply

Your email address will not be published.