A few questions about C++

Hey there all. I'm an aspiring C++ coder like a lot of people here, and aspiring coders usually have questions like myself. (Note, all questions are console related, not with GUI commands)

1.) Launching another program from your program
I have no idea if it is or not, but I would like to know how to launch another program from my own, like a secondary launcher, where if "X" was pressed, "THIS.filetype" would launch. I know this is possible with *.bat files, by typing the directory and then the file name and extension, but it isn't very useful if you only want to launch a certain program and don't want 20 *.bat files on your Desktop or wherever you plan to store it.

2.) Making the program write a file (Updated)
I know this is possible, I've seen programs do it millions of times. I would like to know how to make my executable write a simple text file as a log. Such as when "The answer is ..." appears in my program, it would be dumped into a text file. I got that down, but now I'd like to know how to make it where the program doesn't overwrite the existing contents.
Last edited on
Bump
I don't believe you can just "launch" a program without resorting to some OS specific commands...there might be a library out there with something about that however, you could try searching for "launch program from console app" or something like that.
To write to a file without deleting the old contents, enable the ios::app flag when opening the file.
To launch a file you can use the ShellExecute function from Win API
http://msdn.microsoft.com/en-us/library/bb762153(VS.85).aspx
system("command here");
1) Lookup the function ShellExecute from the Win32 which gives you more possibilities when launching than system()
2) It has all to do with how you open the file, if you open the file in append mode you will not overwrite.
closed account (z05DSL3A)
CreateProcess is another option for item 1)

http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx
Topic archived. No new replies allowed.