运行 vscode 中的 hackerrank 等平台上提供的测试用例如何针对我的 C++ 程序进行测试?

How can run test cases that are provided on platforms like hackerrank etc in vscode to test against my c++ programme?

终端中的测试用例太大 copy/paste。是否有任何方法可以根据 vscode/atom 中的 C++ 代码测试此输入文件?请帮助

创建文本文件并将测试copy/paste 放入相应的文件中。然后,编写一个函数来读取这些测试文件中的信息并将其转换为您要解决的任何问题。这可以使用 STL fstream library 中的 ifstream 对象来完成。

您可以将测试用例保存到一个文件中,然后使用 shell 的管道机制来重定向 std::cin。这样你根本不用修改你的程序。

在 linux(或 WSL 或 mingw bash)上,如果你有一个 test.txt 和你的程序 prog,你可以这样做:

cat test.txt | ./prog

在 windows 上(在 powershell 上),使用 test.txt 和你的程序 prog.exe 它将是

Get-Content .\test.txt | .\prog.exe

您应该按 Download 并将示例输入保存为文件(我称之为 testdata.txt)。然后使用 input redirection (<) 将其作为流程的标准输入提供。以下命令适用于 Windows 和 Unix-like OS'es(假设可执行文件名为 myprog.exe):

< testdata.txt myprog.exe