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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:04:34+00:00 2026-05-23T14:04:34+00:00

I have a char array, in which its contents look something like the following:

  • 0

I have a char array, in which its contents look something like the following:

char buffer[] = "I1 I2 V1 V2 I3 V3 I4 DO V4";

As you may see, it’s a typical blank separated character string. I want to put all sub-string(s) starting with a letter “I” into a vector (IVector), and sort its elements in ascending order. At the same time, I’d also want to put all sub-string(s) starting with a letter “V” into another vector (VVector), and sort its elements in ascending order. The other(s) (e.g. “DO” in this example) will be ignored.

I’m not familiar with STL algorithm library. Are there any functions to help me achieve the avove-mentioned job?

Thank you!

  • 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-23T14:04:35+00:00Added an answer on May 23, 2026 at 2:04 pm

    You can iterate over all the substrings using an std::istream_iterator<std::string>:

    std::stringstream s(buffer);
    std::istream_iterator<std::string> begin(s);
    std::istream_iterator<std::string> end;
    for( ; begin != end; ++begin) {
        switch((*begin)[0]) { // switch on first character 
            // insert into appropriate vector here
        }
    }
    

    Then you can use std::sort to sort the vectors, as @Billy has already pointed out. You could also consider using an std::set, as that will always keep your items sorted in the first place.

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

Sidebar

Related Questions

I have a binary array char buffer[N]; which contains two bytes to be interpreted
i have an char array b[20] which i want to write into a file
I have a big lump of binary data in a char[] array which I
I have a char array buffer that I am using to store characters that
Have an array of chars like char members[255]. How can I empty it completely
if I have an array of pointers like char **lines, how can i determine
I have a 2 dimensional array, like so: char[,] str = new char[2,50]; Now,
i have an array of type char char *arg[100] this array its reading the
I have a char array. I take its address and pass it to a
I have an array of strings which when I iterate through and print its

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.