如何在视觉工作室社区中设置竞争性编程站点等环境?

How to setup environment like competitive programming sites in visual studio community?

本文关键字:编程 竞争性 站点 环境 设置 视觉 工作室 社区      更新时间:2023-10-16

我正在尝试在Visual Studio Community 2017中创建像在线竞争网站(Hackerearth.com,hackerrank.com 和 ideone.com(这样的环境,用于编码实践。

检查此 https://ideone.com/fuSOVO

以下是竞争性编程中 C++ 代码中大多数问题的标准结构。

#include <iostream>
#include <string>
using namespace std;
int main()
{
int t;
cin >> t;
string s;
while (t--) {
cin >> s;
cout << " Hello " << s << "n";
cin.get();
}   
}
input:
5
Sam
Kiara
Victor
Riley
Diva
output:
Hello Sam
Hello Kiara
Hello Victor
Hello Riley
Hello Diva

几乎所有的竞争性编程网站都使用stdin作为默认输入,标准输出作为默认输出,如上所述。

我已经使用本指南 https://www.quora.com/Is-there-a-way-to-compile-and-run-C%2B%2B-in-Sublime-Text/answer/Shubham-Agrawal-131?srid=n9sL 在崇高文本中设置环境。而且它工作得很好。现在我想在Visual Studio Community 2017中设置相同的内容。

我按照本指南将输入管道输入到c ++程序中以在Visual Studio中进行调试,但是我遇到错误。

'FirstProject.exe' (Win32): Loaded 'F:Visual StudioFirstProjectDebugFirstProject.exe'. Symbols loaded.
'FirstProject.exe' (Win32): Loaded 'C:WindowsSysWOW64ntdll.dll'. Cannot find or open the PDB file.
'FirstProject.exe' (Win32): Loaded 'C:WindowsSysWOW64kernel32.dll'. Cannot find or open the PDB file.
'FirstProject.exe' (Win32): Loaded 'C:WindowsSysWOW64KernelBase.dll'. Cannot find or open the PDB file.
'FirstProject.exe' (Win32): Loaded 'C:WindowsSysWOW64msvcp140d.dll'. Cannot find or open the PDB file.
'FirstProject.exe' (Win32): Loaded 'C:WindowsSysWOW64vcruntime140d.dll'. Cannot find or open the PDB file.
'FirstProject.exe' (Win32): Loaded 'C:WindowsSysWOW64ucrtbased.dll'. Cannot find or open the PDB file.
The program '[3764] FirstProject.exe' has exited with code 0 (0x0).

我知道我可以使用文件系统,但是当我必须将代码从本地系统上传到在线编辑器时,我必须更改代码以匹配这些站点的环境。我想在本地创建相同的环境,这样我就不必每次在网站上提交时都更改代码。

添加

输入.txt

到项目和 试试这个

int main(int argc, char *argv[]) {
try
{
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4996) //4996 for _CRT_SECURE_NO_WARNINGS equivalent
freopen("intput.txt", "r", stdin);
#pragma warning(pop)
#endif
int n; // number of workshops
cin >> n;
}
catch (...) {
cout << "Error" << endl;
}
#ifdef _MSC_VER
fclose(stdin);
#endif
return 0;
}

#ifdef 将导致代码不被 VS 之外的编译器使用