Charles Khunt
Charles Khunt

Reputation: 2505

how to open a file (ie. .txt file) in C++ (kinda like double clicking it in windows)?

I'm wondering how I can open a file literally in C++ (like double clicking it)?

Upvotes: 2

Views: 4000

Answers (5)

Gage
Gage

Reputation: 19

easy way: system("notepad.exe [location to file]");

Upvotes: 1

paxdiablo
paxdiablo

Reputation: 881283

Provided you have the ".txt" extension registered (and text files should be associated with Notepad in a default installation, or something else if you've changed it from Explorer - you'd have to work pretty hard to disassociate them), Windows will open it for you without you having to specify the executable name:

ShellExecute (hwnd,"open","c:\\x.txt",NULL,NULL,SW_SHOW);

or, for a web page in your browser of choice:

ShellExecute (hwnd,"open","http://www.microsoft.com",NULL,NULL,SW_SHOW);

Upvotes: 9

Jason Williams
Jason Williams

Reputation: 57892

Use ShellExecute with the "open" verb. See this article for more information.

Upvotes: 2

Gerald
Gerald

Reputation: 23479

Use the ShellExecute function with the "open" operation.

Upvotes: 2

a_m0d
a_m0d

Reputation: 12195

You mean like open explorer?
How about using

system("explorer.exe file.to.open");

Upvotes: 2

Related Questions