Anyone knows how to do this
typedef std::string T_String;
typedef char T_8bit;
typedef short T_16bit;
typedef int T_32bit;
I have defined these typedefs and I want to convert the "T_string" type to short,char and int type.
I have a function like this:
void C_Ptx::Built_AMB(T_String value,bool ChainType)
where I need to convert the 1st parameter to short,char and int type.
How can I do it! please Help.
Kohinoor
Re: Anyone knows how to do this
two options spring to mind:
For a char it is simple - the first character is your 'char'
For the others:
1. Use a C function such as strtol, but you'll need to call c_str() on the string. (No doubt the method Thew would suggest)
2. Create an ostringstream from the string and then use >>
You can do the same with double and also if you have wstring, in which case you use owstringstream instead.
The best things come to those who rate
Re: Anyone knows how to do this
What do you mean by "convert"? If you mean you want to read a value coded in the string, then that's relatively simple:
#include <string>
#include <sstream>
// read an int from a string
std::string s = "12345";
std::istringstream iss(s);
int i;
iss >> i; // i now equals 12345
If, however, by "convert" you mean "cast", then forget it.
He who breaks a thing to find out what it is, has left the path of wisdom - Gandalf
Re: Anyone knows how to do this
"istringstream", surely :-)
He who breaks a thing to find out what it is, has left the path of wisdom - Gandalf
Re: Anyone knows how to do this
yes of course :)
The best things come to those who rate