没有完全从文本文件中读取

Not Fully read from the text file

本文关键字:文件 读取 文本      更新时间:2023-10-16

我正试图从c++文本文件中读取一些整数。奇怪的是,它只读取13个数字,但我的文件包含25个数字。我搜索了,但没有发现任何东西,有人建议添加ios::binary,但不起作用。为什么? ?这是这部分代码。

#include <iostream>
#include <vector>
#include <cmath> 
#include <fstream>
using namespace std;
int main()
{
    ifstream myfile;
    myfile.open("Nvector.txt");
    vector<int> N;
    for(int j=0; j<25; j++)
    {
        int input;
        myfile>> input;
        N.push_back (input);
    }
    system("PAUSE");
    return 0;
}

你可能想检查你正在读取的文本文件,可能有特殊的行尾字符会导致整数从向量中连接/删除,也可能有与向量有关的问题