【问题标题】:MSVS 12, C++, command arguments not workingMSVS 12,C++,命令参数不起作用
【发布时间】:2015-01-30 02:10:18
【问题描述】:

我在 Microsoft Visual Studio 12 中使用 C++。我想传递命令行参数。我尝试在 MSVS 的 Project/Properties/Debugging/Command Arguments 字段中列出它们,并且我也尝试使用 CLIArgsMadeEasy 插件,但它从来没有用过。 argc 始终为 1,其中 argv[0] 是应用程序路径。 示例:给定一个我想用三个 args 启动的 fred.exe 程序:a,b,c 即相当于 cmd 窗口行的

fred.exe a b c

我将提供的编辑框中的参数完全指定为:

a b c

使用上述任何一种方法(MSVS 标准或 CLIArgsMadeEasy),但是当我运行它们时,它们没有通过。

代码是:

#include <iostream> // for standard I/O
#include <string>   // for strings
#include <iomanip>  // for controlling float print precision
#include <sstream>  // string to number conversion
#include <math.h>

using namespace std;

int main(int argc, char *argv[])
{

...

【问题讨论】:

  • 您是否在 VS 中以调试模式运行程序?
  • 项目属性 → 调试 → 命令参数
  • 1) 是的,我在 VS 中运行从调试模式。我正在构建并运行一个版本,因为它不起作用我改为调试。 X64。 2)根据我的帖子,我确实尝试了项目属性→调试→命令参数(之后我安装了 CLIArgsMadeEasy 插件,但没有帮助)
  • 对于其他有类似问题的人,在我的 VS 2015 上,项目属性可能(功能?)在您最近打开的最后一个 上打开。尽管听起来很愚蠢,但人们可能会假设项目属性将打开当前的构建/调试配置,并且他们最终会为正在调试的二进制文件修改命令行参数 not ,这可能会发生(这里有罪)。 TL;DR:检查版本是否在与构建/调试版本相同的 的 cmd args 上

标签: c++ visual-studio-2012 command-line-arguments


【解决方案1】:

我已经在我的视觉工作室中尝试过这个程序,它可以工作:

#include <iostream> // for standard I/O
#include <string>   // for strings
#include <iomanip>  // for controlling float print precision
#include <sstream>  // string to number conversion
#include <math.h>

using namespace std;

int main(int argc, char *argv[])
{
	for(int i = 1; i < argc; i++)
	{
		cout << i << ":" << argv[i] << endl;
	}
	return 0;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-28
    • 2017-06-19
    • 2013-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多