我完成了代码,但问题是我不知道如何根据给出的说明对其进行测试。
讲师为我们提供了 3
个输入文件,其中包含以下值:
文件1:33 20
文件2:5 7
文件3:18 15
我应该获取这些值并使用这些存储的值创建事件对象。问题是讲师在 Ubuntu 上给出了测试方法,她展示了如何在命令行中输入文件,如下所示:
./sApp < simulationShuffled3.in
所以我真的很困惑我应该如何让它工作。我目前正在使用 Windows 控制台、VStudio 和带有终端附件的 sublime text。
我当前使用的代码是我的类(class)笔记示例中的
while (getline(cin >> ws, aLine)) { // while (there is data)
stringstream ss(aLine);
ss >> arrivalTime >> processingTime;
Event newEvent = Event('A',arrivalTime,processingTime);
eventPriorityQueue.enqueue(newEvent);
}
最佳答案
从 Windows [和/或] Linux 中的 stdin
读取输入
您可以通过三种方式做到这一点:
- 在命令提示符中(Windows)
- 在 Powershell (Windows/Linux) 中
- 在 WSL 和 Linux 中
1:在 Windows Cmd 中
type input.in | python file_requiring_input.py # in python
type input.in | go run file_requiring_input.go # in go
type input.in | node file_requiring_input.js # in js
javac file_requiring_input.java &&
type input.in | java file_requiring_input # in java
g++ file_requiring_input.cpp &&
type input.in | a.exe # in cpp
gcc file_requiring_input.c &&
type input.in | a.exe # in c
另一种方式
python file_requiring_input.py < input.in # in python
g++ file_requiring_input.cpp &&
a.exe < input.in # in cpp
2:在 Powershell 中
gc .\input.in | python file_requiring_input.py # in python
g++ .\file_requiring_input.cpp ;
gc .\input.in | .\a.exe # in cpp
gc
is short forGet-Content
. Other aliases ofgc
arecat
andtype
. which means that all three names can be used as replacement or gc
3:使用wsl对于 Windows//Linux 命令
cat input.in | python file_requiring_input.py # in python
g++ file_requiring_input.cpp &&
cat input.in | ./a.out # in cpp
另一种方式
python file_requiring_input.py < input.in # in python
g++ file_requiring_input.cpp &&
./a.out < input.in # in cpp
have edited the code testing everything out hopefully. Do correct me if I am wrong or if anything more is to be added . Also input.in is more generally a text file so you can create input.txt file as you wish and it would work the same
关于c++ - 如何在 Windows 命令行中读取输入 .in 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44867313/