重新打开和 cout 创建内部错误
freopen and cout creating internal error
我正在尝试读取和写入一些文件,但是每次尝试向output.out
文件std::cout
某些内容时,都会收到"错误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 ++,没有矢量大小调整,现已更正(但是错误,在某种程度上仍然存在:代码正在这种状态下编译,但是一旦我尝试输入一个字符串,就会出现同样的问题就像在我的std::cout<< x[j] << h[j] << std::endl;
中添加<<" "
in the std::cout<< x[j] <<" "<< h[j] << std::endl;
假设您将代码放在主块中,代码在 MSVC 15.5.2 中编译良好。证据在这里。
即使编译正常,代码似乎也没有按预期工作。首先,你不能std::cin >> x[j] >> h[j];
.创建一个临时变量来存储输入,然后将其推送回向量:
int input1, input2;
std::cin >> input1 >> input2;
x.push_back(input1);
h.push_back(input2);
您还应该注意,这个循环for (int j = 0; j < n; n++)
永无止境。变量j
应该增加,而不是n
。无论你想要实现什么,这似乎都不是办法。
std::cout 是一个 std::ostream 用于输出到控制台。对于输出到文件,使用了类 std::ifstream 和 std::ofstream。使用以下语法:
std::ifstream [ifstream_name](constructor parameters);
[ifstream_name] >> [container to store file contents];
std::ofstream [ofstream name](constructor parameters);
[ofstream_name] << [contents to write to file];
相关文章:
- 致命错误 C1001 :vs2017 15.8.4 的内部错误(编译器文件"msc1.cpp",第
- mingw32_gt_pch_use_address中的内部错误,在config/i386/host-mingw32.c
- 有关使用标志位设置内部错误标志的说明
- 致命错误 C1001:编译器中发生内部错误。'f:\dd\VCtools\Compiler\cxFE\SL\P1\C\P0io.c'
- 在函数内部错误定位后,从函数中释放返回的指针会导致芯片崩溃
- ssl3_read_bytes:TLSV1警报内部错误,安全套接字,OpenSSL,C ,获取HTTPS页面
- 构建 C++11 代码时 Coverity 中的内部错误
- 重新打开和 cout 创建内部错误
- 使用variadic概念模板时GCC内部错误
- C1001:编译器中包含 <boost/shared_ptr.hpp 时发生内部错误>
- 错误 C1001:编译器中发生内部错误
- CDT 在以下期间发生内部错误: "Setting up indexer"
- 代码块中存在内部错误
- 致命错误C1001:编译器中发生内部错误
- C++致命错误 C1001:编译器中发生内部错误
- 错误 C1001:调试模式下的编译器中发生内部错误
- 致命错误 C1001:尝试使用模板时出现内部错误
- GDB 在启动时崩溃(内部错误:follow_die_offset)
- C++ CodeDOM 解析器错误:行:75,列:57 ---内部错误
- 嵌套类模板专用化未正确匹配+msvc内部错误