【お知らせ】この部分は英語原文のみでの提供となります。何卒ご了承ください。
2.2.3.15.9 string::Format
Contents
Description
Format and store a series of characters and values in the string.
Syntax
void Format( LPCSTR lpcszFormat, ... )
Parameters
- lpcszFormat
- [input] A format-control string.
- ...
- [input] A comma separated list of user specified variables holding data values
Return
none.
Examples
EX1
void string_Format_ex1() { char sz[10] = "abcdefg"; int nn = 10; double dd = 3.1416; string str; str.Format("Results = %s, %d, %5.4f", sz, nn, dd); out_str(str);//Results = abcdefg, 10, 3.1416 }
EX2
// the following usage will generate runtime error due to // incorrect data being used void string_Format_ex2() { string str; str.Format("x1=%f, x2=%f", 5, 3.4); // 5 is not a double, will generate runtime error str.Format("x1=%f, x2=%f", 5.0, 3.4);// this will work correctly }
Remark
This member function formats and stores a series of characters and values in the string. Each optional argument (if any) is converted and output according to the corresponding format specification in lpcszFormat. Please note that it is your responsibility to match the data type with the correct formatting specification.
See Also
Header to Include
origin.h