I'm trying to read in the chars for a file in order to compare two text files. The problem is I can't seem to load space characters into my vectors. Any suggestions for me?

vector<char> cyphVector;
    char c;
    //fill vector with cypher file chars
    while( cyphFile.good() ){
       
       cyphFile >> c;
       cyphVector.push_back(c);
    }

    //fill vector with plain file chars
    vector<char> plainVector;
    char d;
    while(plainFile.good()){
       
       plainFile >> d;
       plainVector.push_back(d);
       cout << d;
    }

Does ifstream::get read whitespace? I think it can. Use .get() instead of using the >> operator. i.e. plainVector.push_back( cyphFile.get() );

Alright that worked. Though there was one problem. An y with . . over it was put at the end. Could you explain that?

EDIT: I also was wondering if I can merge all white space into one ' ' char as far as the vector is concerned.

Alright that worked. Though there was one problem. An y with . . over it was put at the end. Could you explain that?

EDIT: I also was wondering if I can merge all white space into one ' ' char as far as the vector is concerned.

I don't know what you mean here:

An y with . . over it was put at the end.

Is that a Unicode character? A letter with two dots over it?

Regarding the merging of spaces, don't merge them. Simply don't push a space onto the vector if the last character pushed onto the vector was also a space. Throw the second, third, fourth spaces away and grab the next character from the input stream without pushing those spaces onto the vector:

char aChar = cyphFile.get ();
if (aChar == ' ')
{
     // check if top element of vector is a space.  If
     // not, push the space onto the vector.  If it is
     // a space, do nothing.
}
else
     // push aChar onto the vector.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.