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

  • Home
  • SEARCH
  • 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 8073483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:21:10+00:00 2026-06-05T14:21:10+00:00

I have a vector of strings: vectorElements I’d like to create a vector of

  • 0

I have a vector of strings: vectorElements
I’d like to create a vector of *char to point to the beginning of each string. My objective is to be able to traverse through each string, character by character. Ultimately, I’d like to sort the vector of strings.
Note: Strings may contain integer values. In which case, I’ll be sorting based on their numeric value.

  • 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-05T14:21:11+00:00Added an answer on June 5, 2026 at 2:21 pm

    If you are writing in C++, it is better to use C++ string instead of the C style array of char. You can still iterate through each character with by obtaining the iterator with begin() and use overloaded operator ++ on the iterator to traverse to next character (check with iterator returned by end() to know whether you reached the end of the string or not). You can also refer to character in the string in C style with overloaded operator [].

    Therefore, a vector<string> may be what you need.

    To sort the strings, you may want to use sort function in algorithm header. Since you are not sorting them lexically all the time, you have to define your own function that compares between 2 strings.

    Pseudocode for the comparison:

    while (i < str1.length() && i < str2.length())
      if (!isDigit(str1[i]) || !isDigit(str2[i]))
        // Lexical comparison
        if (str1[i] != str2[i])
          i++
        else
          return str1[i] < str2[i]
      else // If both are digits
        // parseInt will parse the number starting from current position
        // as positive integer
        // - It will consume as many characters as possible (greedily) and
        // return the parsed number plus the number of characters consumed
        // - If the number is very large (exceed 64-bit), you may want to 
        // only find the length of the number and write another
        // comparison function for big numbers.
        // The code below assumes no overflow
        (num1, len1) = parseInt(str1, i)
        (num2, len2) = parseInt(str2, i)
        if (num1 == num2)
          i += len1
        else
          return num1 < num2
    
    if (str1.length() == str2.length())
      return false
    else
      return str1.length() < str2.length()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have vector of strings and want to create a fixed with string out
I have a std::vector<std::string> which would contain numbers and characters (single char). I would
I have a function where I have a container which holds strings (eg vector<string>
A have a vector of strings in c++: vector<string> myVect = {A, A, A,
I have a vector of strings: std::vector<std::string> fName which holds a list of file
I have a large collection of unique strings (about 500k). Each string is associated
I have a Vector < String >. Now i want to store those Strings
I have a std::vector of bytes ( char ), I'd like to do the
I have a std::vector<uint8_t> that contains strings at specific offsets. Here's a shortened dump:
I have some data structures: all_unordered_m is a big vector containing all the strings

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.