Function
lexicalCast2
Cast from a String-type to a numerical type
lexicalCast2(TTarget & target, TSource const & source)
lexicalCast2(TTarget & target, String<TValue, TSpec> const & source)
Include Headers
seqan/stream.h
Parameters
target
Object to hold result of cast
Types: double, int, unsigned int, or similar
source
The string to be read from
Types: char[], CharString, or similar, std::string
Remarks
uses istringstream internally, so right now "123foobar" will be succesfully cast to an int of 123
Return Values
true if cast was successful, false otherwise
Types: bool
Examples
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
SeqAn - Sequence Analysis Library - www.seqan.de
 

Page built @2013/07/11 09:12:36