![]() |
|
[C] How to make text file open up in notepad C++ - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C] How to make text file open up in notepad C++ (/showthread.php?tid=5603383) |
How to make text file open up in notepad C++ - Cereology - Apr 19, 2017 How do I make a text document open in c++ Code #include<iostream>* - HFDone - Apr 19, 2017 use system to run cmd start file.txt * - Iterator - Apr 19, 2017 You can use WinApi function ShellExecute https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx to open file with default program. ShellExecute(NULL, L"open", L"Path to your txt file", NULL, NULL, SW_HIDE); * - LanMan - Apr 19, 2017 As someone said you can use ShellExecute, system with cmd or WinExec. Or even CreateProcess cmd.exe with /c parameter and your command * - Hoodie+ - Apr 19, 2017 If you're using standard C libraries you can just use the system() function and just specify the path of the file. * - 0xDEAD10CC - Apr 19, 2017 He did say notepad so if the default file handler for .txt extensions is not notepad.exe this ShellExecute or WinExec suggestion will fail, and same with letting the shell handle a command for you in any other way that doesn't call the notepad.exe program to execute explicitly. Just pass the file as a parameter when executing notepad.exe with something like CreateProcess on Windows. First argument will accept a path to a file you wish to open: Code notepad.exe "C:/filepath/file.txt"* - Mouse❤️ - Apr 19, 2017 For something so simple, just use system(), but don't get comfortable with it. * - 0xDEAD10CC - Apr 19, 2017 (Apr 19, 2017 08:24 PM)Mouse❤️ Wrote: For something so simple, just use system(), but don't get comfortable with it. Anything but a null pointer with that function leads to undefined behavior. He's on Windows (most likely if he's mentioning notepad -- but the path in his example would suggest the same too), he can easily use CreateProcess with notepad.exe and argument matching a filepath. * - Mustys - Apr 20, 2017 I hope this might help. Code var fileToOpen = "SomeFilePathHere";* - Iterator - Apr 21, 2017 (Apr 20, 2017 06:40 PM)Mustys Wrote: I hope this might help. Why you are posting C# code in C++ section * - Mustys - Apr 21, 2017 (Apr 21, 2017 01:03 AM)Iterator Wrote: Why you are posting C# code in C++ section I just realized, was tired and it was late last night? |