For a school assignment I have to implement a project in C++ using Borland C++ Builder.
As the VCL uses AnsiString for all GUI Components I have to convert all of my std::strings to AnsiString for the sake of displaying.
std::string inp = "Hello world!";
AnsiString outp(inp.c_str());
works of course but is a bit tedious to write and ...
Hello,
Windows XP SP3. Core 2 Duo 2.0 GHz.
I'm finding the boost::lexical_cast performance to be extremely slow. Wanted to find out ways to speed up the code. Using /O2 optimizations on visual c++ 2008 and comparing with java 1.6 and python 2.6.2 I see the following results.
Integer casting:
c++:
std::string s ;
for(int i = 0; i < 10...
I have the following function that will convert a string into a numeric data type:
template <typename T>
bool ConvertString(const std::string& theString, T& theResult)
{
std::istringstream iss(theString);
return !(iss >> theResult).fail();
}
This does not work for enumerated types, however, so I have done something like this:
...
I use the boost lexical_cast library for parsing text data into numeric values quite often. In several situations however, I only need to check if values are numeric; I don't actually need or use the conversion.
So, I was thinking about writing a simple function to test if a string is a double:
template<typename T>
bool is_double(cons...
I would like to write something like this, which cannot be compiled:
std::vector<A> as;
std::vector<B> bs( as.size() );
std::transform( as.beginn(), as.end(), bs.begin(), boost::lexical_cast<B> );
But this is not working, so I created a functor which is doing this for me:
template<typename Dest>
struct lexical_transform
{
templat...
Hi
I'm using boost libs for c++ and the function lexical_cast behaves really weird. If I do lexical_cast("0.07513994") it works fine, but if I use my variable which I need to convert, it throws the bad_lexical_cast exception. Here is the code:
string word;
istringstream iss(line);
do
{
string word;
iss >> word;
double ...
Is it safe to ignore exception of boost::lexical_cast when converting int to std::string?
...
I once saw this nice little snippet of code below, here at SO:
template<typename to_t, typename from_t>
to_t lex_cast(const from_t &arg) {
to_t ret;
std::stringstream os;
os << arg;
os >> ret;
return ret;
}
This mimics boost::lexical_cast. Usage:
string tmp = ::lex_cast<string>(3.14);
However, due to the default...