I have a class structure which represents (internally) the data I wish to output to a file.
Some of the member variables are private to the data class so that it ca
Don't always resort to friend function because it can easily break the encapsulation of your class. Once friend, it can access all your private members no matter whether you hope it see or not.
In your case, you can simply provide some public interfaces to return the necessary data to clients which will produce different formats then. Furthermore, you can take a look at famous MVC pattern if you're interested.