Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) Lubuntu GetLubuntuVersion

 

GetLubuntuVersion is a version code snippets to obtain the version of the current Lubuntu distibution.

 

#include <cstdlib>
#include <fstream>
#include <string>
#include <vector>
#include <boost/foreach.hpp>

///GetLubuntuVersion returns the version number of the Lubuntu distribution currently installed.
///From http://www.richelbilderbeek.nl/CppGetLubuntuVersion.htm
const std::string GetLubuntuVersion()
{
  //Save info to tmp.txt
  {
    std::system("cat /etc/*-release > tmp.txt");
  }
  //Read info to std::vector
  std::vector<std::string> v;
  {
    std::ifstream f("tmp.txt");
    std::string s;
    for (int i=0; !f.eof(); ++i)
    {
      std::getline(f,s);
      v.push_back(s);
    }
  }
  //Analyze std::vector
  BOOST_FOREACH(const std::string& s,v)
  {
    if (s.size() > 15
      && s.substr(0,15)=="DISTRIB_RELEASE")
    {
      const int i = s.find_last_of("=");
      return s.substr(i+1,s.size()-(i+1));
    }
  }
  return "";
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict