printf

格式化写入数据到文件。

返回实际写入的字节数。 number

printf(format) printf(format, arg1, arg2, …argN)

格式化字符串。 format true string 格式化参数。 args false any (平台支持的任意类型)

”`javascript function main() { let file = os.open(“trade_log.txt”, “w+”) let price = 100.25 let volume = 1000 let bytes = file.printf(“Price: %.2f, Volume: %d\n”, price, volume) Log(“Formatted bytes written:”, bytes)

file.seek(0, 0)
let data = file.read()
Log("data:", data)                              // data: Price: 100.25, Volume: 1000

// file.printf("| Price: %.2f, Volume: %d\n")   // "| Price: %!f(MISSING), Volume: %!d(MISSING)"
// file.seek(0, 0)
// data = file.read()
// Log("data:", data)

file.close()

}“` 格式化写入交易数据。

{@fun/OS/File/close close}, {@fun/OS/File/puts puts}, {@fun/OS/File/printf printf}, {@fun/OS/File/flush flush}, {@fun/OS/File/tell tell}, {@fun/OS/File/seek seek}, {@fun/OS/File/eof eof}, {@fun/OS/File/read read}, {@fun/OS/File/write write}, {@fun/OS/File/getline getline}, {@fun/OS/File/toString toString}