Function
lexicalCast
Cast from a String-type to a numerical type
Include Headers
seqan/stream.h
Parameters
The string to be read from Types: char[], CharString, or similar, std::string | |
Type to be casted to Types: |
Remarks
Return value undefined if casting fails, see lexicalCast2 for a more robust variant.
This function uses std::istringstream internally, so right now "123foobar" will be
succesfully cast to an int of 123.
Return Values
Value of Type TTarget with casted contents of source
Types: TTarget
Examples
Using lexicalCast<>() is easy but not as robust as lexicalCast2: We cannot detect parsing or conversion errors.
int i = 0;
double = 0;
bool success = false;
u = lexicalCast<unsigned>( "3"); // => u is 3.
u = lexicalCast<unsigned>("-3"); // => u is undefined.
i = lexicalCast<int>("-3"); // => i is -3.
d = lexicalCast<double>("-3.99"); // => d is -3.99.
See Also
SeqAn - Sequence Analysis Library - www.seqan.de