news  A few questions about C++

Console (18)   Link to this post
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
Console (18)   Link to this post
Bump
firedraco (2048)   Link to this post
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.
Bazzy (3180)   Link to this post
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
Zaita (2112)   Link to this post
system("command here");
anders43 (123)   Link to this post
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.
Grey Wolf (1407)   Link to this post
CreateProcess is another option for item 1)

http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx

This topic is archived - New replies not allowed.