Concatenating int value to string ..??

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 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!!

On Saturday 02 November 2013 14:14:18 Rahul Mathur wrote:
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 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_inj ector<boost::bad_lexical_cast>
'
what(): bad lexical cast: source type value could not be interpreted as target Aborted (core dumped) --
Any clue?
Apple01000 cannot be interpreted as an integer, that's why boost::lexical_cast<int>(TagInitial) throws.

I don't think so. It compiled successfully ( $ g++ test.cpp -o test -lboost_system -lboost_thread ) with GCC-Boost v-1.54 but while linking and execution it gives error as shared. I think if I can know - How to support lexical or what is the build command to support lexical analysis of Boost during Boost-v1.54 build process with toolset of gcc? I do see lexical_cast.hpp file in include file of Boost-v1.54 while building. On Sat, Nov 2, 2013 at 2:39 PM, Andrey Semashev <andrey.semashev@gmail.com>wrote:
On Saturday 02 November 2013 14:14:18 Rahul Mathur wrote:
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 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_inj
ector<boost::bad_lexical_cast>
'
what(): bad lexical cast: source type value could not be interpreted as target Aborted (core dumped) --
Any clue?
Apple01000 cannot be interpreted as an integer, that's why boost::lexical_cast<int>(TagInitial) throws.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On Saturday 02 November 2013 15:05:45 Rahul Mathur wrote:
On Sat, Nov 2, 2013 at 2:39 PM, Andrey Semashev
<andrey.semashev@gmail.com>wrote:
On Saturday 02 November 2013 14:14:18 Rahul Mathur wrote:
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
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_i nj>
ector<boost::bad_lexical_cast>
'
what(): bad lexical cast: source type value could not be interpreted
as
target Aborted (core dumped) --
Any clue?
Apple01000 cannot be interpreted as an integer, that's why boost::lexical_cast<int>(TagInitial) throws.
I don't think so.
It compiled successfully ( $ g++ test.cpp -o test -lboost_system -lboost_thread ) with GCC-Boost v-1.54 but while linking and execution it gives error as shared.
I think if I can know - How to support lexical or what is the build command to support lexical analysis of Boost during Boost-v1.54 build process with toolset of gcc? I do see lexical_cast.hpp file in include file of Boost-v1.54 while building.
I don't understand. You get a run time exception. You do know that lexical_cast operates at run time, don't you? PS: Don't top post, please.

YES, it's a run time exception could you suggest how to handle this .. On Sat, Nov 2, 2013 at 3:11 PM, Andrey Semashev <andrey.semashev@gmail.com>wrote:
On Saturday 02 November 2013 15:05:45 Rahul Mathur wrote:
On Sat, Nov 2, 2013 at 2:39 PM, Andrey Semashev
<andrey.semashev@gmail.com>wrote:
On Saturday 02 November 2013 14:14:18 Rahul Mathur wrote:
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
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_i
nj>
ector<boost::bad_lexical_cast>
'
what(): bad lexical cast: source type value could not be interpreted
as
target Aborted (core dumped) --
Any clue?
Apple01000 cannot be interpreted as an integer, that's why boost::lexical_cast<int>(TagInitial) throws.
I don't think so.
It compiled successfully ( $ g++ test.cpp -o test -lboost_system -lboost_thread ) with GCC-Boost v-1.54 but while linking and execution it gives error as shared.
I think if I can know - How to support lexical or what is the build command to support lexical analysis of Boost during Boost-v1.54 build process with toolset of gcc? I do see lexical_cast.hpp file in include file of Boost-v1.54 while building.
I don't understand. You get a run time exception. You do know that lexical_cast operates at run time, don't you?
PS: Don't top post, please.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

BTW' I am using gcc toolset of "gcc version 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC)" with Boost-v1.54. On Sat, Nov 2, 2013 at 3:49 PM, Rahul Mathur <srivmuk@gmail.com> wrote:
YES, it's a run time exception could you suggest how to handle this ..
On Sat, Nov 2, 2013 at 3:11 PM, Andrey Semashev <andrey.semashev@gmail.com
wrote:
On Saturday 02 November 2013 15:05:45 Rahul Mathur wrote:
On Sat, Nov 2, 2013 at 2:39 PM, Andrey Semashev
<andrey.semashev@gmail.com>wrote:
On Saturday 02 November 2013 14:14:18 Rahul Mathur wrote:
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
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_i
nj>
ector<boost::bad_lexical_cast>
'
what(): bad lexical cast: source type value could not be interpreted
as
target Aborted (core dumped) --
Any clue?
Apple01000 cannot be interpreted as an integer, that's why boost::lexical_cast<int>(TagInitial) throws.
I don't think so.
It compiled successfully ( $ g++ test.cpp -o test -lboost_system -lboost_thread ) with GCC-Boost v-1.54 but while linking and execution it gives error as shared.
I think if I can know - How to support lexical or what is the build command to support lexical analysis of Boost during Boost-v1.54 build process with toolset of gcc? I do see lexical_cast.hpp file in include file of Boost-v1.54 while building.
I don't understand. You get a run time exception. You do know that lexical_cast operates at run time, don't you?
PS: Don't top post, please.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On Saturday 02 November 2013 15:49:02 Rahul Mathur wrote:
YES, it's a run time exception could you suggest how to handle this ..
On Sat, Nov 2, 2013 at 3:11 PM, Andrey Semashev
<andrey.semashev@gmail.com>wrote:
On Saturday 02 November 2013 15:05:45 Rahul Mathur wrote:
On Sat, Nov 2, 2013 at 2:39 PM, Andrey Semashev
<andrey.semashev@gmail.com>wrote:
On Saturday 02 November 2013 14:14:18 Rahul Mathur wrote:
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
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_i
nj>
ector<boost::bad_lexical_cast>
'
what(): bad lexical cast: source type value could not be
interpreted
as
target Aborted (core dumped) --
Any clue?
Apple01000 cannot be interpreted as an integer, that's why boost::lexical_cast<int>(TagInitial) throws.
I don't think so.
It compiled successfully ( $ g++ test.cpp -o test -lboost_system -lboost_thread ) with GCC-Boost v-1.54 but while linking and execution it gives error as shared.
I think if I can know - How to support lexical or what is the build
command
to support lexical analysis of Boost during Boost-v1.54 build process
with
toolset of gcc? I do see lexical_cast.hpp file in include file of Boost-v1.54 while building.
I don't understand. You get a run time exception. You do know that lexical_cast operates at run time, don't you?
PS: Don't top post, please.
I'd maintain the counter separately from the prefix string and compose the final string every time it needs to be incremented. PS: Don't top post, please.

Hi, Rahul Mathur wrote:
YES, it's a run time exception could you suggest how to handle this ..
First of all, replying to an email on this mailing list you should answer below the text you're refering too. The way you're doing it now is called top-posting and shouldn't be used here. You can't convert string "Apple01000" to an int because it not represents a number. There is an 'Apple' word there! BTW, your string is probably equal to "Apple10". I'd advise you to run a debugging session in your IDE after placing a breakpoint at the beginning and step each line to see what is happening in the code. Regards, Adam

On Nov 2, 2013, at 4:44 AM, Rahul Mathur <srivmuk@gmail.com> wrote:
I wish to have string (combination of string value and int value) which increments until 100. The code is as below -
[snip code trying to use lexical_cast to parse a string as an int] This question is off topic for the developer's list. That aside, and apart from the other suggestions made about how to use lexical_cast, I'd suggest considering snprintf(); the result will be more efficient. ___ Rob (Sent from my portable computation engine)
participants (4)
-
Adam Wulkiewicz
-
Andrey Semashev
-
Rahul Mathur
-
Rob Stewart