Cpp Solution
Code\n\nclass Solution {\npublic:\n    string convertToBase7(int num) {\n        string ans="";\n        int i;\n        if(num==0)\n        {\n            retu
# Code\n```\nclass Solution {\npublic:\n    string convertToBase7(int num) {\n        string ans="";\n        int i;\n        if(num==0)\n        {\n            return "0";\n        }\n        if (num < 0)\n        {\n            return "-" + convertToBase7(-num);\n        }\n        while(num!=0)\n        {\n            ans=ans+to_string(num % 7);\n            num=num/7;\n        }\n        reverse(ans.begin(),ans.end());\n        return ans;\n    }\n};\n```
['C++']