I want to run file I/O. You want to enter int values one by one for vector and output them.
The input goes in properly, but a strange number is output when outputting. Can you help me?
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;
void saveOrder(vector<int> ex)
{
    ofstream fout("ex.txt");
    if (!fout.is_open()) {
        cerr << "fail" << endl;
        return;
    }
    for (vector<int>::iterator it = ex.begin(); it != ex.end(); it++) {
        fout << *it << " ";
    }
}
vector<int> loadOrder()
{
    vector<int> ex2;
    ifstream fin("ex.txt");
    if (!fin.is_open()) {
        cerr << "fail";
        return ex2;
    }
    while (!fin.eof()) {
        cout << fin.get() << endl;
        ex2.push_back(fin.get());
    }
    return ex2;
}
int main() {
    vector<int> ex;
    ex.push_back(1);
    ex.push_back(2);
    ex.push_back(3);
    saveOrder(ex);
    vector<int> ex3;
    ex3 = loadOrder();
    for (vector<int>::iterator it = ex3.begin(); it != ex3.end(); it++) {
        cout << *it << endl;
    }
}
 
    