In this post we explained writing in a file using the C# language. In this post we will explain how to do that in unmanaged C++.
So, we are creating a C++ console application, you can use Dev C++ for compiling this code.
Here is the code.
int main() { ofstream fw; fw.open("text.txt"); fw << "Some texxxxxxxxxt." << endl; fw << "tab\ttab, and a new line\n...." << endl; }
We include the fstream library, it contains the ofstream and ifstream classes. They are used for writting and reading to/from files.
Then, in the main function we create an object from ofstream class, and with function open we tell the object that we will write in the file "text.txt".
We write some text to file (check the new line and tab characters).
In the end we close the handle.
This will be written in the file
Some texxxxxxxxxt. tab tab, and a new line ....
If you do not want to erase all text from the file and then write to it again, just make this change
fw.open("text.txt", ios::app);








{ 2 comments… read them below or add one }
Hi I am an effective money maker(not online) by making softwares using VB Can i blog in code it well how to make money (not online) using Vb(visual basic)
We do not want spammers as bloggers.