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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:51:44+00:00 2026-05-31T22:51:44+00:00

As part of a homework assignment I need to concatenate certain values in an

  • 0

As part of a homework assignment I need to concatenate certain values in an array in C++. So, for example if I have:

int v[] = {0,1,2,3,4}

I may need at some point to concatenate v[1] -> v[4] so that I get an int with the value 1234.

I got it working using stringstream, by appending the values onto the stringstream and then converting back to an integer. However, throughout the program there will eventually be about 3 million different permutations of v[] passed to my toInt() function, and the stringstream seems rather expensive (at least when dealing with that many values). it’s working, but very slow and I’m trying to do whatever I can to optimize it.

Is there a more optimal way to concatenate ints in an array in C++? I’ve done some searching and nearly everywhere seems to just suggest using stringstream (which works, but seems to be slowing my program down a lot).

EDIT: Just clarifying, I do need the result to be an int.

  • 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-31T22:51:46+00:00Added an answer on May 31, 2026 at 10:51 pm

    Pseudo code for a simple solution:

    int result = 0;
    for (int i=0; i < len(v); i++)
    {
      result = result*10 + v[i];
    }
    

    Large arrays will bomb out due to int size overflow.

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

Sidebar

Related Questions

so this is part of my homework assignment. need some help with it. my
As part of a homework assignment, we are supposed to create an array that
(this is indirectly a part of a much larger homework assignment) I have something
As part of a homework assignment, I have to program a simple chess game
I need little help on a homework assignment. I have to create a 10
As part of a homework assignment, I have to write a C program in
Some classmates and I are working on a homework assignment for Java that requires
This is part of a homework assignment. What we have to do is write
I have a graph like this: As part of a homework assignment I want
I have a homework assignment in which I need to compute the edit distance

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.