fn() lexicalCast2
Cast from a String-type to a numerical type

Defined in <seqan/stream.h>
Signature bool lexicalCast2(target, source);


target Object to hold result of cast.
source The string to be read from. Type: SequenceConcept.

Return Values

bool true if cast was successful, false otherwise.

Detailed Description

Uses istringstream internally, so right now "123foobar" will be succesfully cast to an int of 123.


Using lexicalCast2 is straightforward and we can detect errors.

unsigned u = 0;
int i = 0;
double = 0;
bool success = false;
success = lexicalCast2(u, "3");      // => success is true, u is 3.
success = lexicalCast2(u, "-3");     // => success is false, u is undefined.
success = lexicalCast2(i, "-3");     // => success is true, i is -3.
success = lexicalCast2(d, "-3.99");  // => success is true, d is -3.99.

See Also