writing in text file

how to use fstream library to write in text file ?
I tried this code but it does not show print anyting in text file

1
2
3
4
5
6
7
8
9
10
11
12
#include<fstream>
int main()
{
	int id=0;
	ofstream fin;
	fin.open("Data1.txt",ios::out);
	while(id<5)
	{
		++id;
		fin<<1;
        }
}
Does it create a file?
I don't know if i properly understand the question , Data1.txt file already exists and is empty
ok i found it u didn't write fin.close(); i didn't know writing that was mandotary
Thanks anyway
Well, I ONLY know how to create and create & insert text onto your local images, including PNG, JPEG, GIF, TIFF and BMP with the help of following demo methods in vb.net application.

http://www.rasteredge.com/how-to/vb-net-imaging/image-drawing-text/

Public Sub TextDrawing(s As String, font As Font, brush As Brush, point As PointF)
End Sub

And more related guides on image drawing and writing library.

http://www.rasteredge.com/how-to/vb-net-imaging/image-drawing/
Even though it was solved I wanted to remark on something....
keskiverto wrote:
Does it create a file?

Unless something has changed, ofstream should always creates the file even if you don't end up writing to it. As I believe ofstream.open("file", ...); automatically creates the file.

Double checking.....yeah..using a slightly modified version of his code:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <fstream>

int main()
{
	int id = 0; 
	std::ofstream fin;
	fin.open("KESKIVERTO.CHECK");
	while(id < 5){
		++id;
	}
	fin.close();
	return 0;
}
:~/projects/cpp/tests/verto$ ls
keskiverto.cpp
:~/projects/cpp/tests/verto$ g++ -o keskiverto keskiverto.cpp
:~/projects/cpp/tests/verto$ ls
keskiverto  keskiverto.cpp
:~/projects/cpp/tests/verto$ ./keskiverto
:~/projects/cpp/tests/verto$ ls
keskiverto  KESKIVERTO.CHECK  keskiverto.cpp
:~/projects/cpp/tests/verto$ cat KESKIVERTO.CHECK
:~/projects/cpp/tests/verto$ 
Topic archived. No new replies allowed.