opening a file (word, notepad, excel etc.) in c++

Sep 9, 2010 at 11:57pm
I've been searching to no avail on how to open up a file in c++. I want to open something like a word file or a notepad file. An external file. How is it that i can open a file such as in c++?
Sep 10, 2010 at 12:09am
Sep 15, 2010 at 12:45am
i mean like to open it in a seperate window, not for input or output
Sep 15, 2010 at 12:57am
Then launch the application with the file in the command line. Make sure to put the file path between "quotes".
Sep 15, 2010 at 1:44am
I'm having a little trouble following you, can you give an example please?
Sep 15, 2010 at 2:18am
Well... I'm gonna hate myself in the morning for this, but...

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

-Albatross
Sep 15, 2010 at 2:59am
quick and very dirty code
system("notepad file.txt");
Sep 15, 2010 at 7:01pm
that's so close, I was so excited to see a notepad file pop up lol

Do you know how to open up an already existing file?
Sep 15, 2010 at 11:07pm
ShellExecute mentioned bu Albatross above, uses the file associations to open a file using the correct app.
Sep 15, 2010 at 11:11pm
@blackcoder41:
STOP.
You have violated the C++ coding dogma.
Repent or burn forever in the hell known as GAS Assembly.

Okay, jk, but system() is evil. ;)

-Albatross
Last edited on Sep 15, 2010 at 11:26pm
Sep 15, 2010 at 11:56pm
Albatross wrote:
STOP.
You have violated the C++ coding dogma.
Repent or burn forever in the hell known as GAS Assembly.

Okay, jk, but system() is evil. ;)
When a person can't be good they turn to the devil, lol
Sep 16, 2010 at 2:12am
at this point, I'm so frustrated it's whatever works lol
Sep 16, 2010 at 8:36am
Each OS has different way of associating files with programs. As such, there's no generic way to code it unless you wrap the possible methods with a generic function, which isn't the case here.

In Windows the method is to call ShellExecute. If you don't want to call it for religeous reasons, you'll just end up duplicating its functionality. There's more to programming than abstracting every nuance of every operating system.
Topic archived. No new replies allowed.