亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C++讀取文件內容如何使用vector容器進行讀取?

C++讀取文件內容如何使用vector容器進行讀?。?
查看完整描述

4 回答

?
慕斯709654

TA貢獻1840條經驗 獲得超5個贊

1

2

3

4

vector<unsigned char> data;

ofstream f("in.dat", ios::binary);

unsigned char c;

while(f>>c) data.push_back(c);

 


查看完整回答
反對 回復 2019-03-27
?
米脂

TA貢獻1836條經驗 獲得超3個贊


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

include <vector>

#include <iostream>

using namespace std ;

typedef struct Data

{

        unsigned char idrecord[11]; //id

        unsigned char ctype[7]; //type

        unsigned int od;

        unsigned char id;

} data_t ; //這個類型要定義成全局的!

int main()

{

    data_t d[]={

        { "111","10",1,11},

        { "222","11",2,22},

        { "333","12",3,33}

    };

    vector <data_t> vst ;

    int i;

    for( i=0;i<3;i++ )

        vst.push_back( d[i] );

    for( i=0;i<3;i++ )

    {

        cout << vst[i].idrecord <<endl;

    }

    return 0;

}

 


查看完整回答
反對 回復 2019-03-27
  • 4 回答
  • 0 關注
  • 863 瀏覽

添加回答

了解更多

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號