system("cmd /c start out.txt"); // 方式一
system("out.txt"); // 方式二
cmd /c start out.txtcmd.exe,執行內部命令 start。start 會根據文件關聯(如 .txt 關聯 Notepad)在**新視窗**啟動應用程序。/c 參數表示執行完命令後關閉 cmd 視窗。start /min 最小化、start /max 最大化、start /wait 等待結束。system("out.txt")cmd /c 隱式執行)。PATHEXT 環境變量與文件關聯,行為等同於在 cmd 中直接輸入 out.txt 回車。system() 最終調用 CreateProcess 啟動 cmd.exe /c "命令"。
start 是 cmd 內部命令,會解析文件關聯(HKEY_CLASSES_ROOT\.txt)並啟動關聯程序(如 notepad.exe out.txt)。
system("out.txt") 即可。ShellExecute (Windows API) 或 start "" "program.exe" "args"。xdg-open (Linux)、open (macOS)、start (Windows) 封裝函數。兩者本質相同,均通過文件關聯啟動默認程序。start 提供更豐富的啟動控制選項;直接文件名更簡潔。生產代碼建議使用平台原生 API(ShellExecute/CreateProcess/fork+exec)而非 system(),避免安全風險與性能開銷。