Avatar ·

在 Visual Studio 中调试带命令行参数的 C++ 应用程序

大家好!我是一名初学 C++ 的开发者,正在编写一个用于处理文本文件的小型控制台应用程序。程序需要通过命令行接收文件路径和工作模式标志。以下是简化后的代码: ```cpp #include #include #include int main(int argc, char* argv[]) { if (argc < 3) { std::cerr << "Usage: program.exe \n"; return 1; } std::string filepath = argv[1]; std::string mode = argv[2]; std::ifstream file(filepath); if (!file.is_open()) { std::cerr << "Error: cannot open file " << filepath << "\n"; return 1; } // ... 根据模式处理文件 ... std::cout << "Processing file: " << filepath << " in mode: " << mode << "\n"; return 0; } ``` 问题在于,从 Visual Studio 启动(F5 或 Ctrl+F5)时,程序无法接收命令行参数。我知道可以从命令行启动...