QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

The PRINT (file statement) statement prints numeric or string expressions to a sequential file, IO port or device.

Syntax

PRINT #fileNumber&, [ [expression] [{; ,] … ]

Parameter(s)

Usage

Example(s)

Prints data to a text file sequentially and reads it back to the program screen as one line of text.


filename$ = "testfile.dat" 
x = 1: y = 2: z$ = "Three" 

OPEN filename$ FOR OUTPUT AS #1 'opens and clears an existing file or creates new empty file 

PRINT #1, x, y, z$ 

CLOSE #1 

PRINT "File created with data. Press a key!" 

K$ = INPUT$(1) 'press a key 

OPEN filename$ FOR INPUT AS #2 'opens a file to read it 

LINE INPUT #2, text$ 

CLOSE #2 

PRINT text$ 
WRITE text$

END 

File content: PRINT (file statement) string file values will not include the enclosing quotation marks but can be read by LINE INPUT (file statement) as text.


 1             2            Three 

Screen output: PRINT string values will not display enclosing quotation marks. WRITE screen displays will.


 1             2            Three
" 1             2            Three"

See Also