Hi,

Can anybody tell me that how can i open file and write it in winform C++? i have googled alot and searched msdn but could not find appropriate help. I also tried using fstream's objects but they were declared unidentified on winform. what can i just do? what stream class should i use? please also specify its header file.

Any help will be highly appreciated. thanks.

Its idential to any other c++ program.

#include <fstream>
...
...
<snip>
            std::ofstream out("test.txt");
            if( out.is_open() )
            {
                out << "Hello world\n";
                out.close();
            }

i have tested this simple piece of code before. actually, in winform compiler is not detecting fstream. it is giving error of "unidentified object". is there any other object like fstream? i have read about "STREAMREADER" and "STREAMWRITER" in msdn. are they useful in winform?

what compiler are you using? I used Visual Studio and had no problems. Using VC++ 2010 Express I created a C++/CLR Windows Forms project then added that code.

i actually used visual c++ 2008 express. also on visual studio 2008, but compiler raised error in detecting stream object. well i dont know which compiler i m using, well i m trying to figure out my mistake. i will post message after some days seeing situation. thanx 4 help.

my thread has been solved. first at top i included to detect StreamWriter:

using namespace System::IO;

then in any button click event, i wrote the following code:

StreamWriter ^ sr=gcnew StreamWriter("test.txt");
sr->Write(textBox1->Text);
sr->Close();

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.