0
#include <iostream>
#include <fstream>
using namespace std;


void LOGMSG(string test)
{
	ofstream log;
	log.open("text.txt");
	log << test.c_str();
}

int main()
{
	

	LOGMSG("this is a test");
	LOGMSG("this is a test2");
	LOGMSG("this is a test3");
}

but it's only writes the last line i mean the last time i called the func!!
how can i make it write every thing every time i call the func?
thnx

Edited by Mr_PoP: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by MasterGberry
0
#include <iostream>
#include <fstream>
using namespace std;


void LOGMSG(string test)
{
	ofstream log;
	log.open("text.txt", ios::out | ios::app); // the ios::out means its an output, and the ios::app means Append (Add to the end of the file)
	log << test.c_str();
}

int main()
{
	

	LOGMSG("this is a test");
	LOGMSG("this is a test2");
	LOGMSG("this is a test3");
}
0
#include <iostream>
#include <fstream>
using namespace std;


void LOGMSG(string test)
{
	ofstream log;
	log.open("text.txt", ios::out | ios::app); // the ios::out means its an output, and the ios::app means Append (Add to the end of the file)
	log << test.c_str();
}

int main()
{
	

	LOGMSG("this is a test");
	LOGMSG("this is a test2");
	LOGMSG("this is a test3");
}

thnx dude :)

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.