【发布时间】:2018-01-16 10:38:35
【问题描述】:
我正在尝试读取和写入一些文件,但每次我尝试将 std::cout 某些内容添加到我的 output.out 文件时,我都会收到“错误 C1001,编译器中发生内部错误”。
为什么?
(我在预处理器定义中使用了_CRT_SECURE_NO_WARNINGS,以便能够使用freopen())
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <deque>
#include <array>
#include <vector>
freopen("C:\\somepath\\input.in", "r", stdin);
freopen("C:\\somepath\\output.out", "w", stdout);
int t;
std::cin >> t;
std::cout << t << std::endl;
for (int i = 0; i < t; i++)
{
int n;
std::cin >> n;
std::cout << t << std::endl;
std::vector <int> x, h;
x.resize(n);
h.resize(n);
for(int j=0;j<n;j++)
{
std::cin >> x[j] >> h[j];
std::cout<< x[j] << h[j] << std::endl;
}
}
编辑:正如 Nighteen 所说,我的代码中有一些错误(n++,没有调整矢量大小,现已更正)
但是该错误仍然以某种方式存在:
代码正在此状态下编译,但是一旦我尝试输入 cout 字符串,就会出现相同的问题
比如在我的std::cout<< x[j] << h[j] << std::endl;中添加<<" "
in the std::cout<< x[j] <<" "<< h[j] << std::endl;
【问题讨论】:
-
将你的代码放入
main函数中。 -
我有一个主函数,我只是没有粘贴它
-
你能给我们一个你想要的例子 input.in 和对应的 output.out 吗?
-
codechef.com/problems/DEFOREST 该页面中有输入/输出示例^^
标签: c++ compiler-errors cout freopen c1001