Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

file

io

windows

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

like image 923
Charles Khunt Avatar asked Dec 21 '25 02:12

Charles Khunt


2 Answers

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);
like image 179
paxdiablo Avatar answered Dec 22 '25 17:12

paxdiablo


You mean like open explorer?
How about using

system("explorer.exe file.to.open");
like image 35
a_m0d Avatar answered Dec 22 '25 15:12

a_m0d



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!