我正在尝试在视觉工作室社区2017中创建像在线竞争网站(Hackerearth.com,hackerrank.com和ideone.com)这样的环境,以进行编码练习。
下面是竞争性编程中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作为默认输入,stdout作为默认输出,如上所述。
我已使用本指南https://www.quora.com/Is-there-a-way-to-compile-and-run-C%2B%2B-in-Sublime-Text/answer/Shubham-Agrawal-131?srid=n9sL在Sublime Text中设置environemt。它工作得非常好。现在我想在Visual Studio Community 2017中设置相同的内容。
我遵循了本指南Piping input into a c++ program to debug in Visual Studio,但我收到了错误。
'FirstProject.exe' (Win32): Loaded 'F:\Visual Studio\FirstProject\Debug\FirstProject.exe'. Symbols loaded.
'FirstProject.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'FirstProject.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'FirstProject.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'FirstProject.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140d.dll'. Cannot find or open the PDB file.
'FirstProject.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. Cannot find or open the PDB file.
'FirstProject.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file.
The program '[3764] FirstProject.exe' has exited with code 0 (0x0).
我知道我可以使用文件系统,但是当我必须将代码从本地系统上传到在线编辑器时,我必须更改代码以匹配这些网站的环境。我想在我的本地创建相同的环境,这样我就不必每次在网站上提交时都更改代码。
答案 0 :(得分:0)
添加
input.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
之外不被编译器使用