I'm adapting a console based program to GUI. 

The console program reads a text file and "compiles" it. 

My GUI application reads the text file and displays in a RichTextBox. 

I'm looking for a method to treat the RichTextBox as a C++ `std::istream`. This would allow me to use code from the console program without modifying it. 

I searched the web and StackOverflow and didn't find any solutions for treating a RichTextBox as an `std::istream`.

Does anybody know of any Winforms library functions that would allow treating of RichTextBox as an `std::istream`?

**My ideas:** 

1. Create an adapter to treat RichTextBox as a stream.
2. Change the console program to pass a "getline" function to the
compiler portion, and have two getline functions (one as the
std::getline, another to get a line from the RichTextBox).
3. Write the RichTextBox contents to a file and feed the file to the
compiler.

I'm using Visual Studio 2010 on Win 7 using ".NET" 4.0, **using C++** *(don't suggest any C# techniques as I'm not fluent in translating)*.