#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 5 Years Ago by Mr_PoP: n/a

#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");
}
#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.