0

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.

2
Contributors
5
Replies
7
Views
7 Years
Discussion Span
Last Post by great_learner
0

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();
            }

Edited by Ancient Dragon: n/a

0

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?

0

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.

Edited by Ancient Dragon: n/a

0

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.

0

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();

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.