c++, using get and >> for ifstream
<p>I have a text file that I am inputting data in from, but I can't seem to get it right.</p>

<p>Here are two lines from the text file as an example (these aren't real people don't worry):</p>

<pre><code>Michael    Davidson     153 Summer Avenue        Evanston        CO 80303
Ingrid     Johnson      2075 Woodland Road       Aurora          IL 60507
</code></pre>

<p>Here is the code I have to load the text file and put the data into a struct.  I am still new to C++(obviously) and I'm having a hard time using get and >> together.  The code I have below, works fine until I get to the "state" and then something goes wrong.  Thanks for the help!</p>

<pre><code>//constants
const int FIRST_NAME_LEN = 11;
const int LAST_NAME_LEN = 13;
const int ADDRESS = 25;
const int CITY_NAME_LEN = 16;
const int STATE_LEN = 3;

//define struct data types
struct CustomerType {
    char firstName[FIRST_NAME_LEN];
    char lastName[LAST_NAME_LEN];
    char streetAddress[ADDRESS];
    char city[CITY_NAME_LEN];
    char state[STATE_LEN];
    int zipCode;
};

//prototype function
ifstream&amp; getInfo(CustomerType&amp; CT_Struct, ifstream&amp; infile);

int main() {

    //declare struct objects
    CustomerType CT_Struct;

    ifstream infile("PGM951_customers.txt");
    if(!infile) {
     cerr &lt;&lt; "Could not open the input file." &lt;&lt; endl;
     exit(1); //terminates the program
    }

//call the function
getInfo(CT_Struct, infile);

return 0;
}

ifstream&amp; getInfo(CustomerType&amp; CT_Struct, ifstream&amp; infile) {

    while(infile) {
     infile.get(CT_Struct.firstName, sizeof(CT_Struct.firstName));
     infile.get(CT_Struct.lastName, sizeof(CT_Struct.lastName));
     infile.get(CT_Struct.streetAddress, sizeof(CT_Struct.streetAddress));
     infile.get(CT_Struct.city, sizeof(CT_Struct.city));
     infile.get(CT_Struct.state, sizeof(CT_Struct.state));
     infile &gt;&gt; ws;
     infile &gt;&gt; CT_Struct.zipCode; 

     cout &lt;&lt; CT_Struct.firstName &lt;&lt; " | " &lt;&lt; CT_Struct.lastName &lt;&lt; " | " &lt;&lt; CT_Struct.streetAddress  
      &lt;&lt; " | " &lt;&lt; CT_Struct.city &lt;&lt; " | " &lt;&lt; CT_Struct.state  &lt;&lt; " | " &lt;&lt; CT_Struct.zipCode &lt;&lt; endl;
    }

return infile;

}
</code></pre>

<p>=== edit ===========
Reading in the state at 8 char was just me messing around and then I forgot to change it back...sorry.</p>
