Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » Disable/re-enable printf()/Cout() console output (Useful if you need to shut up a library)
Disable/re-enable printf()/Cout() console output [message #54540] Tue, 11 August 2020 11:09
koldo is currently offline  koldo
Messages: 3354
Registered: August 2008
Senior Veteran
void ConsoleOutputDisable(bool disable) {
#ifdef PLATFORM_WIN32
	if (disable)
		freopen("nul", "w", stdout);
	else
		freopen("CONOUT$", "w", stdout); 
#else
	static int saved_id = Null;
	static fpos_t saved_pos;
	
	if (disable) {
		fflush(stdout);
		fgetpos(stdout, &saved_pos);
		saved_id = dup(fileno(stdout));
		close(fileno(stdout));
	} else {
		if (!IsNull(saved_id)) {
			fflush(stdout);
			dup2(saved_id, fileno(stdout));
			close(saved_id);
			clearerr(stdout);
			fsetpos(stdout, &saved_pos); 
		}
	}
#endif
}


Best regards
IƱaki

[Updated on: Tue, 11 August 2020 11:15]

Report message to a moderator

Previous Topic: Set text colour in command line
Next Topic: It's incredibly simple to initialize an U++ Vector
Goto Forum:
  


Current Time: Thu Mar 28 11:52:31 CET 2024

Total time taken to generate the page: 0.00983 seconds