luna
luna

Reputation: 133

What is the output destination of ofstream?

In the following C++ function:

void save_data(std::ofstream& csv) {
    csv << "a message";
}

Something I don't understand: if save_data is called, where does it write to? To a file? How exactly is it used?

Upvotes: 1

Views: 369

Answers (1)

Loki Astari
Loki Astari

Reputation: 264471

An ofstream represents a file on the file system:

int main()
{
    ofstream  file("Plop.txt");

    save_data(file);
}

Upvotes: 3

Related Questions