在C ++中读取错误(分隔)的整数

时间:2017-02-01 15:27:51

标签: c++

我试图从白色空格分隔的文本文件中读取几个整数,但是我弄错了,我想知道原因。

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int nums[10]={0};
    ifstream read ("test.txt");

    for (int i=0; i<10; i++) {
        read >> nums[i];
        cout << nums[i] << " ";
    }

    return 0;
}

文字档案:

  

9995 683 74634

输出:

  

9995 6 83 7 4634 0 0 0 0 0

0 个答案:

没有答案