我确信这是一个非常简单的问题 - 我一直在到处寻找答案,但我认为我的问题是我不知道在搜索时使用正确的术语。
我目前正在使用 C++ 为一门课程做作业。本质上,我需要将文件读入 C++ 程序,执行一些操作,然后创建输出 - 我已经完成了所有这些操作。我只是通过
fstream file;
file.open("file.txt");'
在 .cc 文件本身中使用来访问该文件,并且工作正常。然而,我刚刚在这项作业的说明中看到,这不是讲师测试程序的方式 - 相反,他们只会像这样运行我的可执行文件:
<代码>./程序< file.txt
我熟悉在 C++ 程序中使用命令行参数,并且在运行 ./program file.txt
时我能够使程序正常工作(只需传递文件作为参数),但我不知道如何按照讲师要求的方式进行操作。更糟糕的是,我不知道如何实际搜索答案,因为我还不知道正确的术语(同时我才刚刚开始 UNIX 课程的前几周)。
有人能帮助我指出正确的方向吗?非常感谢!
I'm sure this is an extremely simple issue - I've been searching for an answer everywhere but I think my problem is that I don't know the right terminology to use while searching.
I'm currently working on an assignment for a class using C++. Essentially, I need to read a file into a C++ program, do some stuff, and create an output - I've done all of this already. I was accessing the file by just using
fstream file;
file.open("file.txt");'
in the .cc file itself, and that was working fine. However, I just saw in the instructions for this assignment that this is not how the instructor will be testing the program - instead, they will simply run my executable like this:
./program < file.txt
I'm familiar with using command line arguments within C++ programs, and I'm able to make the program work no problem when running ./program file.txt
(just passing the file as an argument), but I can't figure out how to do it the way the instructor is asking for. Worse off, I can't figure out how to actually search for the answer since I don't know the correct terminology yet (I'm simultaneously only in the first few weeks of my UNIX class).
Is anyone able to help point me in the right direction? Thanks a bunch!
发布评论