1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to copy data from ifstream to a vector<char> ?

Discussion in 'MFC' started by RYoung992, Jun 26, 2010.

  1. RYoung992

    RYoung992 New Member

    Jun 26, 2010
    Likes Received:
    Trophy Points:
    How can I copy the data from an ifstream to a vector<char> ?

    The input file holds an array, so it contains something to the effect of:

    The function I've written can read this and copy "10" to an array size variable, then the contents of the array between {} to a c-string. However with a c-string, the size must be constant, so I cannot use the variable from the input file to define it. This is why I am trying to use a vector.

    I've tried this:
    int mSize = // data read from file, in example above, 10
    mapFile.ignore(25, '{');
    int vSize = mSize*2;			// vector size is twice the map size
    vector<char> mDataV(vSize);		// map Data Vector
    char mDataC[21];			// map Data C-string
    mapFile.getline(mDataC, vSize+1, '}');	// copy ifstream to mDataC
    mDataV.push_back(mDataC);		// copy mDataC to mDataV
    But this returns error C2664, saying it cannot convert mDataC from char[21] to const char &. I understand what this means but not how to resolve it. I tried replacing mDataC with *mDataC, and this compiled, but no data was copied to mDataV (it was empty, and no map was drawn on the screen).


Share This Page