0

So I have an array of strings called blog[] and I'm trying to use a string from the array at position i, like:

outfile << blog[i];

But the problem is that blog[i] is of type MicroBlog (MicroBlog is a class I'm working with)

So my question is how can I convert from type MicroBlog to type string?

Here is the method I'm trying to use blog[i] in:

bool MicroBlog::SaveBlog(const string filename, const MicroBlog &AnotherMicroBlog)
{

    ofstream outfile;
    outfile.open(filename.c_str());


    num_tweets = AnotherMicroBlog.num_tweets;
    for (int i=0; i < num_tweets; i++)                 
    {


                outfile << blog[i];             
        outfile.close();
        }             




}

1 Answers1

1

You have to write your own operator ie toString() or overload <<:

 class Microblog {

     ....

     std::string toString() const { //public
          string ret = all_the_data;
          return ret;
     }
 };

And then outfile << blog[i].toString();

yizzlez
  • 8,757
  • 4
  • 29
  • 44