-
Strings
I use Visual C++. Is there a string class in STL so that i can use it for data type identifier for example like "string my_variable;". And one more question: How is it possible to convert a string value to double or float? can any one show me the simplest pseudocode?
Thanks
-
The STL string is in the header file "string" so just:
Look up stringstreams for converting strings to X data type.
EDIT: Don't forget string is in the std namespace.
-
The simplest pseudocode might be:
std::istringstream istr(myStringVar);
istr >> myDoubleVar;
Although you might want to add error checking. You can also use atoi or atof if you don't care about error checking: myDoubleVar = std::atof(myStringVar.c_str());
-
what are delimiters and tokeniser???
-
A delimeter is a character that marks the end (or beginning) of a piece of data. If we had the string:
"The quick brown fox jumps over the lazy dog."
and we read to the delimeter 'x', we would have
"The quick brown fo"
A token is essentially the data that exists between the delimeters. A tokenizer is an algorithm that parses a string into tokens. If we were to use a tokenizer on the string:
"2x-12=48"
with the delimeters being '-' and "=", then we would get the resulting tokens, "2x","12", and "48".
-
I am satisfied with the explanation. Thank you.