2013/11/2 Rahul Mathur <srivmuk@gmail.com>
All,

I wish to have string (combination of string value and int value) which increments until 100. The code is as below -

---
#include <iostream>
#include <cstdlib>
#include <string>
#include <boost/lexical_cast.hpp>

using namespace std;

int main() {
        std::string TID = "Apple";
        int TagID = 01, Value = 000 /* 100 IDs*/;
        std::string TagName, TagInitial, TagUId;
        TagName = TID + boost::lexical_cast<std::string>(TagID); // Should be as -> Apple01
        TagInitial = TagName + boost::lexical_cast<std::string>(Value); // Should be as -> Apple01000
        int i = boost::lexical_cast<int>(TagInitial) + 1; // Should be as -> Apple01001
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                       I think this is throwing the exception, the cast seems invalid
 
        TagUId = boost::lexical_cast<std::string>(i);
        std::cout << "Tag ID .." << TagUId << endl;
}

I get below error message -

--
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_lexical_cast> >'
  what():  bad lexical cast: source type value could not be interpreted as target
Aborted (core dumped)
--

Any clue?

~ Thanks!!

_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users



--
Daniel

D'un coté s'étend le bien, de l'autre, le vide de la vie quotidienne. (F.Alberoni)