Questions tagged [lexical-cast]
69 questions
5
votes
2 answers
What overhead is there in performing an identity boost::lexical_cast?
Given a function such as:
template< typename T >
void function1( const T &t )
{
function2( boost::lexical_cast(t) );
}
What kind of overhead is incurred if the type passed to function1 is already a std::string?
Does the overhead…

Drew Dormann
- 59,987
- 13
- 123
- 180
4
votes
4 answers
Stringstream to vector
I'm wondering what the best way to write from an std::stringstream into a vector.
Here's an example of what's in the stringstream:
"31 #00 532 53 803 33 534 23 37"
Here's what I've got:
int buffer = 0;
vector analogueReadings;
stringstream…

Jean-Luc
- 3,563
- 8
- 40
- 78
4
votes
1 answer
Is there a way to use SFINAE to determine if a call to a templated function would fail due to the types provided?
I have a templated class that I am using to provide a method that will use boost::lexical_cast to cast its std::string parameters to the type specified in the template, only if the lexical cast is possible. Currently to check if it's possible I'm…

Cassie Dee
- 3,145
- 2
- 18
- 11
4
votes
2 answers
boost::lexical_cast and stringification of non-builtin types
I have a (maybe) simple problem about boost::lexical_cast with composite types (in my case std::vector.
My first version of a templatized stringification function was the following
template
std::string stringiy(const T…

linello
- 8,451
- 18
- 63
- 109
4
votes
1 answer
Precision is lost when using lexical_cast(string)
When using boost::lexical_cast (I'm using boost version 1.58 on VS2013), I can't get the exact value specified in the string, even though it is represent-able in float:
std::wstring t = L"91.25";
float r;
r = boost::lexical_cast(t);
r is…

omasoud
- 411
- 5
- 11
4
votes
1 answer
boost::lexical_cast cannot handle negative numbers?
This short C++ program behaves in a way which baffles me:
#include
#include
#include
#include
int main(void) {
signed char c = -2;
assert(c == -2);
c = boost::lexical_cast

quant_dev
- 6,181
- 1
- 34
- 57
4
votes
1 answer
boost lexical cast string to double
I am facing a conversion issue for which I'd like your help. I'm using gcc4 compiler and I am quite restricted to use gcc4.
I want to convert std::string to double.
std::string aQuantity = aRate.getQuantity();
std::string aAmount =…
user1400995
4
votes
1 answer
Boost spirit floating number parser precision
There is something strange I noticed when comparing boost::lexical_cast and boost spirit parsing.
I'm trying to parse a string into float. for some reason spirit gives very imprecise result. for example: when parsing string "219721.03839999999"…

kreuzerkrieg
- 3,009
- 3
- 28
- 59
3
votes
1 answer
boost::lexical_cast compiles with warnings
Compiling the following:
// file main.cpp
#include
#include
int main()
{
boost::lexical_cast( 656.16 );
return 0;
}
yields to this:
/usr/local/include/boost/lexical_cast.hpp:1184: warning:…

Vahagn
- 4,670
- 9
- 43
- 72
3
votes
1 answer
specializing boost::lexical_cast for enums in boost::property_maps
I am trying to use a boost::graph that has an enum inside its bundled vertex property. The problem starts when I try to use the bundled property for a boost::dynamic_property. Looks like I can't get the correct template specialization for…

Slizzered
- 869
- 2
- 9
- 23
3
votes
1 answer
Enable boost::lexical_cast to throw out of range error for values smaller than double range
boost::lexical_cast throws errors for values larger than the maximum value of double. But for numbers smaller than minimum value, it silently makes it zero. How do I enable out of range errors for later case(i.e. If a number is smaller than…

g-217
- 2,069
- 18
- 33
3
votes
1 answer
How to implement Casts utility namespace
Say I generate a Casts namespace which will hold numerous casts functions:
namespace Casts
{
// To string
bool Cast(bool bValue, string& res);
bool Cast(int intValue, string& res);
bool Cast(float…

idanshmu
- 5,061
- 6
- 46
- 92
3
votes
7 answers
How to use the boost lexical_cast library for just for checking input
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…

Inverse
- 4,408
- 2
- 26
- 35
2
votes
4 answers
Convert C++Builder AnsiString to std::string via boost::lexical_cast
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…

leen
- 8,568
- 3
- 23
- 18
2
votes
1 answer
Using boost::lexical_cast with custom operator<< in namespace
Given two namespaces which each provide a specialization of operator<< for std::vector, is it possible to use boost::lexical_cast? I know the code will work if I promote one of the operators into the global namespace, but that just causes an…

tgoodhart
- 3,111
- 26
- 37