is it possible to write from a functio to a file

I got this piece of code and I've been trying to take the result of this function and write to a file but everything I tried is just a failure. Is it possible to display this function in a file call customer.txt for example. Any help with this. Also, I read this http://www.cplusplus.com/doc/tutorial/files/ but I don't get it, any advise to how to write and read from a file. thanks a lot.

void storeCustomer(CarCustomer arrCustomers[], CarCustomer carCustomer, int count)// I want to display in a file.
{
for (int index=0; index<count; index++)
{
cout<< arrCustomers[index].lastName << ","
<< arrCustomers[index].firstName << " \t"
<< setw(10)<< right<<fixed<< setprecision(2)<< arrCustomers[index].price <<"\t"
<< translateCarTypeToText(arrCustomers[index].CarType) << endl;
closed account (N36fSL3A)
Why are you outputing to the console instead of the file?
> how to write and read from a file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <fstream>

int main()
{
    // write to a file
    {
        // open the file for output
        std::ofstream fout( "filename.txt" ) ;

        // use the file exactly like you would use std::cout
        fout << 1234 << ' ' << "hello world\n" ;
    }

    // read from a file
    {
        // open the file for input
        std::ifstream fin( "filename.txt" ) ;

        // use the file exactly like you would use std::cin
        int i ;
        fin >> i ;
    }
}


Go through this tutorial: http://www.mochima.com/tutorials/fileIO.html
Topic archived. No new replies allowed.