I have output from my program.
I need it to be sent directly to Notepad or any other word processor.
How can I do that?
it's really important--thanks.
I have output from my program.
I need it to be sent directly to Notepad or any other word processor.
How can I do that?
it's really important--thanks.
Short answer: write the output to a file, close/flush it, then launch an editor on that file. was right to point toward file I/O, and 's idea of launching Notepad is fine — but using the OS API to open the file is safer and more portable than calling system() directly.
Notepad is a GUI program and does not read from stdin, so piping (for example prog | notepad) will not work. Use a temporary or named file, ensure the file handle is flushed and closed, then open the file with the platform API. On Windows, ShellExecute is a simple way to open the file with the default text editor (or to run Notepad explicitly). CreateProcess or ShellExecute also avoid command-line injection risks that come with system().
Example (Windows) — open the written file with the default handler:
#include <windows.h>
bool OpenFileWithDefaultApp(const char* path)
{
HINSTANCE result = ShellExecuteA(NULL, "open", path, NULL, NULL, SW_SHOWNORMAL);
return (INT_PTR)result > 32; // >32 indicates success
} Practical tips and gotchas:
system() to avoid injection and quoting problems.open, Linux desktops use xdg-open (or desktop-specific helpers) to launch the default viewer — run those via safe APIs or carefully constructed commands.These steps make the approach robust across environments while addressing the common pitfalls discussed in the thread.
Jump to Post— Clinton Portis 211Including the library will give ye' the tools you need to read and write to a file. Specifically, creating an object of type 'ofstream' will allow you access to library functions that write to a file.
Including the library will give ye' the tools you need to read and write to a file. Specifically, creating an object of type 'ofstream' will allow you access to library functions that write to a file.
And after writing the output to a file call system() (or some other similar os-specific function) to launch Notepad, for example
system("Notepad myfile.txt"); We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.