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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:38:09+00:00 2026-05-28T20:38:09+00:00

Do I need to sort my vector if the items were read in from

  • 0

Do I need to sort my vector if the items were read in from a file sequentially that was already sorted? I don’t want to incur the performance penalty if it’s unnecessary. For reference, this is what I’m using to build it, and each item is in order as it’s being read in.

Edited after @dribeas’ comment

std::vector<int> split(const std::string &s, char delim) {
    std::vector<int> elems;
    std::stringstream ss(s);
    std::string item;
    while(std::getline(ss, item, delim)) {
        elems.push_back(static_cast<int>(atoi(item.c_str())));
    }
    return elems;
}
  • 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-28T20:38:10+00:00Added an answer on May 28, 2026 at 8:38 pm

    No, you don’t need to sort the vector. push_back adds elements to the end explicitly.

    Note that your API is taking in elems and also returning it (by reference). What happens to any content the vector already contains?

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

Sidebar

Related Questions

I need to write a sort of key-logger function that can be called from
i need to sort a large XML file and i've been reading that placing
I need some sort of node-graph editor, that hopefully works on both Mac and
I need to sort an array that can look like this: $array[4][0] = array('id'
I have an array of filenames and need to sort that array by the
I need to sort a C++ std::vector<std::string> fileNames . The fileNames are labeled as
I need some sort of an algorithm, that would try to find free space
I have a bunch of strings that I need to sort. I think a
i have a vector of vertices from mygraph, and i topologically sort the vertices.
I have a need to wrap a vector iterator, but don't like the idea

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.