/*和c的轉換函數比起來用法更爲隱蔽,對初學者來說不夠直觀。*/
#include "iostream"
#include "sstream"
#include "string"
#include "cstdlib"
using namespace std;
int main(void)
{
/*以下是內置類型向string轉換的解決方案*/
int ival;
char cval;
ostringstream out_string;
string str;
ival = 100;
cval = 'w';
out_string << ival << " " << cval;
str = out_string.str();
cout << str << endl;
/*以下是string向內置類型轉換的解決方案*/
int itmpe;
char ctmpe;
str = "100k";
istringstream in_string( str );
in_string >> itmpe >> ctmpe;
cout << itmpe << " " << ctmpe << endl;
system( "PAUSE" );
return 0;
}