ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • dat파일에저장하기
    TIL(today i learned)/C++ 2020. 10. 4. 18:41

    *dat파일이란 2진수로저장되어저있는 파일이다*

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    #include<iostream>
    #include<fstream>
    #include<string>
    #include<vector>
    using namespace std;
    class my
    {
    public:
        string one;
        string two;
    };
    int main(void)
    {
        int count = 0;
        vector <my>vec;
        ofstream writeFile;
        ifstream readFile;
        string a;
        string path = "test.dat";    //파일 열기
        char d[100];
        
        readFile.open(path);
        while (!readFile.eof())
        {
            vec.push_back(my());
            getline(readFile, a);
            //cout << a << endl;
            for (int i = 0; i < a.length(); i++)
            {
                if (a[i] == ' ')
                {
                    count++;
                    continue;
                }
                switch (count)
                {
                case 0:
                    vec.back().one += a[i];
                    break;
                case 1:
                    vec.back().two += a[i];
                    break;
                default:
                    break;
                }
            }
            count = 0;
        }
        for (vector<my>::size_type i = 0; i < vec.size(); i++)
        {
            cout << vec[i].one << " " << vec[i].two << endl;
        }
        readFile.close();
        return 0;
    }
    cs

     

     

    'TIL(today i learned) > C++' 카테고리의 다른 글

    Flood-Fill algorithm  (0) 2020.09.11
Designed by Tistory.