中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

C++讀取文件,將文件內(nèi)容讀取到struct中

2018-07-20    來源:open-open

容器云強(qiáng)勢上線!快速搭建集群,上萬Linux鏡像隨意使用

struct定義:

#include "stdafx.h"
//內(nèi)存對齊1字節(jié)
#pragma pack(1)

struct Day
{
    int DateTime;
    int Open;
    int High;
    int Low;
    int Close;
};
#pragma pack()

指針讀。
// Test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "Day.cpp"
#include <sys\stat.h>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    fstream f;
    const char* filename = "e:\\t.dat";
    f.open(filename,ios::binary|ios::in);

    struct _stat info;
    _stat(filename,&info);
    int filesize = info.st_size;
    const int SIZE_OF_DAY = sizeof(Day);
    cout<<"sizeof(Day)="<<SIZE_OF_DAY<<endl;
    const int days_count = filesize/sizeof(Day);
    cout<<"day_count="<<days_count<<endl;
    Day* day = new Day[days_count];
    //Day* dayTemp=day;
    for(int i=0;i<days_count;i++)
    {
        Day* p2Day = day + i;
        f.read((char*)p2Day,SIZE_OF_DAY);
        cout<<p2Day->DateTime<<endl;
        cout<<p2Day->Close<<endl;
    }
    f.close();
    delete[] day;
    system("pause");

    return 0;
}

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:C++使用內(nèi)存映射文件入門

下一篇:Sql Server 分區(qū)sql