【发布时间】:2014-09-23 19:33:27
【问题描述】:
假设我有以下 C++ 代码
#include <iostream>
int main()
{
int x,y;
std::cout << "Please enter the first input." << std::endl;
std::cin>>x;
std::cout << "Please enter the second input." << std::endl;
std::cin>>y;
std::cout<<x/y<<std::endl;
return 0;
}
我可以用cl/EHsc sample.cpp从命令行编译文件
我想要做的是用命令行给出的输入显示程序的输出。我该怎么做?
x 应该从第一个命令行参数中获取它的值,
y 应该从第二个命令行参数中获取它的值。
以下应该可以,但我想避免摆弄 Visual Studio 属性等。
Piping input into a c++ program to debug in Visual Studio
编辑:另外为了进一步澄清,我想将它用作一个自动化系统,它从命令行接收输入,我不想修改原始代码
【问题讨论】:
-
argv[1] 和 argv[2] 不起作用?
-
我应该补充一点,我不想修改代码本身,我编辑了问题,这是一个有效的观点。
-
写一个shell脚本包装器?
-
您能否详细说明或举个例子,shell 脚本包装器如何将命令行参数传递给可执行文件(作为标准输入)?
-
echo "arg1 arg2" | ./yourprogrnamehere(等等,VS/Windows;nm)
标签: c++ visual-studio debugging