Laxical

xiaoxiao2021-03-06  62

#include

#include

#include

#include

#include

Using namespace std;

USING NAMESPACE BOOST;

Int main (void)

Try {

// The following is a solution for built-in type to String conversion

// Lexical_cast advantage is obvious

INT IVAL;

CHAR CVAL;

Ostringstream out_string;

String str0;

String str1;

IVAL = 100;

CVAL = 'w';

OUT_STRING << ival << "<< CVAL;

STR0 = OUT_STRING.STR ();

Str1 = lexical_cast (ival)

Lexical_cast (CVAL);

COUT << str0 << endl;

COUT << str1 << endl;

// The following is a String solution to a built-in type conversion

// It is still inadequate compared to Stringstrem.

// I don't know what idea you have>?

Int itmpe;

CHAR CTMPE;

STR0 = "100K";

STR1 = "100H";

IstringStream in_string (str0);

IN_STRING >> ITMPE >> CTMPE;

Cout << itmpe << "<< CTMPE << endl;

ITMPE = Lexical_cast (str1);

CTMPE = lexical_cast (str1);

System ("pause");

Return 0;

}

Catch (Bad_Lexical_cast E)

{

Cout << E.WHAT () << endl;

cin.get ();

}

转载请注明原文地址:https://www.9cbs.com/read-112163.html

New Post(0)