#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

#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 :)

Glad to be of service :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.