这段代码有什么问题?我无法从文件中读取矢量。表达式:矢量下标超出范围
What's wrong with this code? I can't read vector from file. Expression: vector subscript out of range
你好,我对这个复制迭代器有问题,我不知道如何正确编写复制迭代程序。我得到的只是这个错误:"表达式:矢量下标超出范围"。我的程序总是停在std::copy行。无论如何,我的编译器不会显示任何警告和其他错误。
ifstream fin("aFileName", ios_base::in | ios_base::binary);
std::vector< aClass > aVector;
std::copy(std::istream_iterator<aClass, char>(fin),
std::istream_iterator<aClass, char>(), aVector.begin());
也许我程序的流部分写得不好。但我没有收到任何错误,也没有收到任何警告信息。
ofstream fout("aFileName", ios_base::out | ios_base::binary);
std::copy(aVector.begin(), aVector.end(),
std::ostream_iterator<aClass, char>(fout, " "));
我为我的英语感到抱歉。
向量可以直接从迭代器中构造。不需要使用std::copy
。
std::vector<aClass> aVector(std::istream_iterator<aClass>(fin), (std::istream_iterator<aClass>()));
相关文章:
- 使用新行和不使用新行读取文件
- 读取文件并输入到矢量中
- 读取文件的最后一行并输入到链接列表时出错
- 为什么在读取文件大小时文件IO速度会发生变化
- 读取文件时运行时的未知行为
- 如何逐行读取文件,每行中的内容都用空格分隔并将其写入新文件中
- 读取文件中所有可能的十六进制 16 字节序列并打印每个序列
- C++ 读取文件读取文件不正确
- 读取文件并将其存储在unordered_map中时出现问题
- 读取文件时无法使用 OpenMP 获得加速
- 使用istringstearm和get行缓慢读取文件
- 如何继续读取不同功能中的文件,而不是从头开始再次读取文件?
- 读取文件时引发异常
- 从标准输入读取文件后读取用户输入
- 在读取文件后重置句柄
- 如何在C++编译时读取文件?
- std::ifstream 在读取文件中最后一项时设置 eofbit,但仅在读取数值类型时发生
- 读取文件在第二次调用时返回INVALID_HANDLE
- 通过指针读取文件
- 逐行读取文件,并将数据插入变量和数组中