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++:

  1. ofstream ofs
  2. ofs.open("output.txt")
  3. write(ofs, "hello, world!")
  4. ofs.close

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

n++ example

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

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

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