Help with ofstream

So, I'm trying to write a program that will parse data from a few text files, append them, send the new string to a class, and then spit the worked text back out into another file. Here's the pertinent part of the main()

1
2
3
4
5
6
7
8
Product myProduct;

myProduct.SetAllTheThings(Master);

myProduct.Display();
std::cout << std::endl;

MyOutFile << myProduct.GetAllTheThings() << '\n';


Now, using the myProduct.Display(), I can see that all of the Setters are writing the strings to the appropriate variables, but the GetAllTheThings() method isn't outputting them to the output file.

The GetAllTheThings() method just looks like:

1
2
3
4
5
6
Product::GetAllTheThings()
{
  return this->GetProductNum();
  ...
  return this->GetImageURL();
}


and those individual methods are just returning the variables.

So for the question, can you use a getter with ofstream? Or should I re-work this to simply create a string and output that with ofstream?
GetAllTheThings immediately returns this->GetProductNum(), so it won't do anything more after that. Why do you have multiple return statements in succession like this?
Well the GetProductNum() gets the ProductNum_ variable like this:

1
2
3
4
Product::GetProductNum()
{
   return this->ProductNum_;
}


and there's about 20 variables that need to be returned, so I nest them inside GetAllTheThings so I don't have to write

 
MyOutFile << myProduct.GetProductNum() << myProduct.GetProductName() << myProduct.etc() << myProduct.GetImageURL() << '\n'
Well, the thing is that the only thing that function will ever do is return this->GetProductNum();. None of the other return-statements will be executed.
That's what I figured, I'm writing it now to overload the << operator to do force it to do what I want. So I'm putting this in my class.cpp (and the prototype in class.h)

1
2
3
4
5
6
std::ostream & operator<<(std::ostream & os, const Product & myProduct)
{
  os << myProduct.ProductNum_ << '\t' << myProduct.ProductNameNew_ << '\t';
  
  return os;
}


and then this in my main works:

 
MyOutFile << myProduct;
Topic archived. No new replies allowed.