Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8713609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:23:00+00:00 2026-06-13T05:23:00+00:00

So I got asked this on a skills test for an internship, and at

  • 0

So I got asked this on a skills test for an internship, and at the time it completely baffled me. I have some code now that I thought should work, but isn’t assigning the correct values to the string.

#include <iostream>
#include <string>
using namespace std;

int main()
{
     // declarations
     int i = 0, num= 63;
     string b="";

     while (num != 0)
     {
          i = num % 10;
          b.insert(0,i + 48 + "");
          num = num/10;
     }


     cout << b << endl;

     return 0;
}

With “num” being the integer value (I just used 63 as an example)

EDIT:: I incorrectly paraphrased, I could not use any function that did an int to string conversion for me, not that I couldn’t use the string library, my mistake.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:23:02+00:00Added an answer on June 13, 2026 at 5:23 am

    Change the insert line to

    b.insert(0, 1, '0' + i);
    

    This will insert the character obtained from adding i to '0' once at index 0 in the string.


    Explanation of why your code isn’t working:

    b.insert(0,i + 48 + "");
    

    the line above is calling

    basic_string::insert( size_type index, const CharT* s );
    

    where the pointer is being determined by adding 48 + i to the address of the "" string literal, resulting in garbage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked this question a while ago and got an answer that I thought
I have already asked this question on ServerFault however I got very minimal replies....one
Got this as an interview question from Amazon to test basic SQL skills and
I have asked this question sometime back. But havent got a solution yet, Here
I recently asked this question https://softwareengineering.stackexchange.com/questions/129076/go-instead-of-c-c-with-cgo and got some very interesting input. However there's
I recently asked this question here and got some great answers! Custom SQL GROUP
I have asked this question before but I haven't got an answer, so I'm
I recently asked this question on here and got the answer. However I'm now
I have already asked this question in offical Flot google groups, but got no
A time ago I already asked this question and I also got a good

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.