0
 int main()
{
shape a;           //make class

ostream out;
out.open("test.txt");      // make file
out<< a.draw();           // std::ostream << void        error
                          // draw() { cout<<"ddd"<<endl; }
out.close();
}

I want to wirte draw() in to file. can you help me?

khoho
  • 1

1 Answers1

0

You have two options.

1: Pass the stream to the function and write to that instead of std::cout

void draw(std::ostream& os) { os << "ddd\n"; }

int main()
{
    std::ofstream s("test.txt");
    draw(s);
}

2: Return the result instead of writing it

std::string draw() { return "ddd\n"; }

int main()
{
    std::ofstream s("test.txt");
    s << draw();
}
molbdnilo
  • 64,751
  • 3
  • 43
  • 82