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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:10:28+00:00 2026-05-15T04:10:28+00:00

Comparing version numbers as strings is not so easy… 1.0.0.9 > 1.0.0.10, but it’s

  • 0

Comparing version numbers as strings is not so easy…
“1.0.0.9” > “1.0.0.10”, but it’s not correct.
The obvious way to do it properly is to parse these strings, convert to numbers and compare as numbers.
Is there another way to do it more “elegantly”? For example, boost::string_algo…

  • 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-15T04:10:28+00:00Added an answer on May 15, 2026 at 4:10 am

    I don’t see what could be more elegant than just parsing — but please make use of standard library facilities already in place. Assuming you don’t need error checking:

    void Parse(int result[4], const std::string& input)
    {
        std::istringstream parser(input);
        parser >> result[0];
        for(int idx = 1; idx < 4; idx++)
        {
            parser.get(); //Skip period
            parser >> result[idx];
        }
    }
    
    bool LessThanVersion(const std::string& a,const std::string& b)
    {
        int parsedA[4], parsedB[4];
        Parse(parsedA, a);
        Parse(parsedB, b);
        return std::lexicographical_compare(parsedA, parsedA + 4, parsedB, parsedB + 4);
    }
    

    Anything more complicated is going to be harder to maintain and isn’t worth your time.

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

Sidebar

Related Questions

Is there a standard idiom for comparing version numbers? I can't just use a
When comparing two strings in c# for equality, what is the difference between InvariantCulture
The Version class in .Net does not implement the CompareTo interface as I would
I keep making attempts at properly using HTML5 but I feel like it's still
Is there a FOSS batch compiling solution for Delphi that takes version as an
I was using mysql++ library and compiling with GCC 3.3.4. That GCC version had
Comparing string in C# is pretty simple. In fact there are several ways to
Comparing LinkedLists and Arrays while also comparing their differences with sorted and unsorted data
When comparing an HTTP GET to an HTTP POST, what are the differences from
I'm comparing between two techniques to create partitioned tables in SQL 2005. Use partitioned

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.