gpt4 book ai didi

c - 使用 Visual Studio 2010,如何向 Visual C++ Win32 控制台应用程序提供输入?

转载 作者:太空宇宙 更新时间:2023-11-04 07:41:26 26 4
gpt4 key购买 nike

我正在使用 Visual Studio 2010 Pro 进行简单的 C 编程,我想知道如何在无需手动操作的情况下向程序提供输入。我习惯工作的环境是您的标准命令行 Unix 环境。一旦我编译了一个 C 文件调用“inputsInts”,它就变成了“a.out”,为了测试输入,我会输入:

简单的方法

echo 1 2 3 4| ./a.out //to provide inputThe number of ints input was 4 //output

The easier way

more input.txt| ./a.out //to provide inputThe number of ints input was 4 //output

The tedious way

./a.out//now I would manually type1 2 3 4 s //in this case I have to type a letter to move onThe number of ints input was 4 //output

Hard is how I have to do it in Visual Studio 2010. I would like to be able to just input in an area the input ahead of time or at least have it read a text file. Obviously I can't test large sets of data by manually typing it in. At the moment I am just doing the coding in VS2010 and going to the unix enviroment to do most testing. I would like to stay in the VS2010 enviroment until I am ready to do a final test in Unix.

I have altered the question quite a bit since I first posted, so the original answers may seem off a bit. Again I appretiate everyone's time and help.

This is just the simple code for an example: #include

int main ()  {
int x, n = 0;
while (scanf("%d", &x)==1)
n++;
printf("The number of ints input was %d\n", n);
return(0);
}

最佳答案

当您启动一个新的 Visual Studio 项目时,您需要创建一个“控制台应用程序”。这将为您提供一个从 Windows 命令提示符窗口运行的程序,也称为 Cmd 窗口,以在其下运行的 shell 程序的名称命名。命令窗口在Windows XP下位于Programs->Accessories下,其他版本的Windows不清楚。打开命令窗口后,其工作方式将与您在 Linux 上习惯的方式类似。

cd MyProject
echo 1 2 3 4|.\MyProject.exe
MyProject.exe <input.txt

关于c - 使用 Visual Studio 2010,如何向 Visual C++ Win32 控制台应用程序提供输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3754772/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com