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 7086161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:30:55+00:00 2026-05-28T07:30:55+00:00

I have a string of numbers in C++: like string str=1234567012 I wish to

  • 0

I have a string of numbers in C++: like string str=”1234567012″

  1. I wish to copy this to an int array, such that each element of the array will have one digit. Now I can use an iterator, and iterate one at a time and use static_cast<int>(*iter). But is there any more easier and straightforward method?

  2. finally i want to recopy the int array to a string array.

Please help me with above 2 steps.

  • 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-05-28T07:30:56+00:00Added an answer on May 28, 2026 at 7:30 am

    You can use the std::transform function:

    std::vector<int> ints(str.size());
    std::transform(str.begin(), str.end(), ints.begin(),
                   [](char c) { return c - '0'; });
    

    If your compiler doesn’t support lambdas yet, you can use a regular function:

    int get_digit(char c) { return c - '0'; }
    
    // ...
    std::transform(str.begin(), str.end(), ints.begin(), get_digit);
    

    To do the reverse operation, you can do similarly:

    std::string s(ints.size(), 0);
    std::transform(ints.begin(), ints.end(), s.begin(),
                   [](int i) { return i + '0'; });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a plist that looks like this: <dict> <key>Aaron</key> <dict> <key>number</key> <string>1234</string> <key>country</key>
I have this string of numbers var array = 1,6,2,9,5 which is retrieved from
I'm parsing a string of 15 digits like this: String str = 100004159312045; int
I have a string in ruby like this: str = AABBCCDDEEFFGGHHIIJJ01020304050607080910 # 20 letters
I have a string that looks like this: 7-6-4-1 or 7 or That is,
Assume I have a set of numbers like 1,2,3,4,5,6,7 input as a single String
Hi I have a string of numbers separated by commas, 100,200,300,400,500 that I'm splitting
I have this string in R: numbers <- 4 4956 1.00e-09 50.9 1.244 47.1
I have a list that has some chapter numbers in string. When I sort
I would like to put an int into a string . This is what

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.