0

I'm using MSVC9 in Rhapsody to build my model into an executable. I try to use <iostream> to log different things in a text file as my model is running for post-treatment. According to a tutorial about iostream I found, I have an operation that does this:

ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();

When building, I get an error that the fstream type is unknown.

I also tried to have an attribute that is declared with type <iostream>::fstream called myfile, removing the first line of my operation's code. Of course, I added both <iostream> and <fstream> to the standard headers of my executable (still according to the tutorial).

How could I get this to work ? Thanks everyone !

Dhafeuwst
  • 1
  • 1
  • well, are you using "using namespace std"?, if not, you should use std::ofstream. BTW, if you copy the exactly error you are getting maybe someone can help you a little more. – Miguel Angel Jan 19 '16 at 15:20
  • 2
    The name is `std::ofstream`. I don't know where you got `::ofstream` from, it's not even in that header, but never mind. And please don't get into the bad habit of [`using namespace std;`](http://stackoverflow.com/q/1452721/1171191). – BoBTFish Jan 19 '16 at 15:24
  • Both solutions work. Thank you both ! – Dhafeuwst Jan 20 '16 at 15:34

0 Answers0