fn: stream.open
[contents]

Contents

Syntax

The syntax for stream.open calls is:

f++:  
name.open(path)
stream.open(name, path)

n++:  
@name.open(path)
@stream.open(name, path)

Description

The stream.open function takes two parameters specifying:

  • the name of a variable of type ifstream, fstream and ofstream; and
  • the path to open
As a member function it takes a single parameter specifying the path to open.

Note: For large scale projects you will find specifying the !mf option to not add member functions during definitions and using stream.open is faster than using the open member function.

f++ example

Examples of stream.open being used with f++:

ofstream ofs
ofs.open("output.txt")
write(ofs, "hello, world!")
ofs.close

ofstream ofs
stream.open(ofs, "output.txt")
write(ofs, "hello, world!")
ofs.close

n++ example

Examples of stream.open being used with n++:

@ofstream ofs
@ofs.open("output.txt")
@write(ofs, "hello, world!")
@ofs.close

@ofstream ofs
@stream.open(ofs, "output.txt")
@write(ofs, "hello, world!")
@ofs.close