2

I'm sorry if this is a question that's already come up, but I searched and couldn't find anything - is there a way in the C++ standard library to get an ostream (or an istream, depending on what you want) from a FILE*?

Something along the lines of

FILE* something;
auto out = hypothetical(something);
out << "Hello world" << std::endl;
Cubic
  • 14,127
  • 5
  • 42
  • 88
  • 1
    Some ideas [here](http://stackoverflow.com/questions/2746168/how-to-construct-a-c-fstream-from-a-posix-file-descriptor). – jrok Dec 17 '13 at 10:58

1 Answers1

0

Depending on compiler, you probably can just do the following:

FILE* f = fopen(myFile, "w+");
std::fstream myStream(f);
myStream << "Hello World\n";
SashaZh
  • 114
  • 4
  • 1
    The "depending on compiler" part kinda makes this a non-option for me. I'm writing non-toy programs that have to work cross platform and cross compiler. – Cubic Dec 17 '13 at 12:32
  • Are you implying that all windows-only programs are "toy"? :) Anyway, I did some research, and it seems to me, that there's no cross-platform solution. – SashaZh Dec 17 '13 at 18:33
  • No, I'm implying I'm writing cross platform applications that aren't toys. – Cubic Dec 18 '13 at 10:00