How can I ignore spaces from the input file?
<p>How can I remove spaces from the input ?? It is an integer array.
the input is like this:</p>

<pre><code>5 6 2 9
3 1 11 4
</code></pre>

<p>I will have to take it as an integer. Then sort it using bubble sort. Problem is I am getting outputs like these: <code>9 8 7 4 2 1 -858993460 -858993460 -858993460 -858993460</code></p>

<pre><code>class inout
{
public : 
    int i[10];

    inout()
    {

    }

    void read()
    {
        ifstream inClientFile( "input.txt", ios::in );
        if ( !inClientFile )
            {
            cerr &lt;&lt; "File could not be opened" &lt;&lt; endl;
            exit( 1 );
            }
        int n=0;

        while (inClientFile &gt;&gt; i[n])
        {

            n++;
        }
        cout &lt;&lt; " Data read complete" &lt;&lt; endl;
    }

    void write()
    {
       ofstream outClientFile( "output.txt", ios::out ); 

       if ( !outClientFile ) {  
          cerr &lt;&lt; "File could not be opened" &lt;&lt; endl;
          exit( 1 );

       } 


        int n=0;
        for (int l=0 ; l &lt; 10 ; l++)
        {
          outClientFile &lt;&lt; i[l] &lt;&lt; " " ;

        }   
        cout &lt;&lt; " Data Write complete"  &lt;&lt; endl;
    }

    void sortData(int asc )
    {
        int pos=0;
        int temp;
        temp = i[0];

        // asending 

        if (asc == 1)
        {
        for (int p = 0; p &lt; 10 ; p ++ )
        {

        int pos=p;
        int temp2,temp = i[p];
            for (int j = p+1 ; j &lt; 10 ; j ++ )
            {
                if (pos == p)
                {
                    if (i[p] &gt; i[j])
                    {
                        pos = j;
                        temp = i[j];
                    }
                }
                else {
                    if (i[pos] &gt; i[j])
                    {
                        pos = j;
                        temp = i[j];
                    }
                }
            }

            temp2 = i[pos];
            i[pos] = i[p];
            i[p] = temp2;
        }


    }
    else
    {
        for (int p = 0; p &lt; 10 ; p ++ )
        {

        int pos=p;
        int temp2,temp = i[p];
            for (int j = p+1 ; j &lt; 10 ; j ++ )
            {
                if (pos == p)
                {
                    if (i[p] &lt; i[j])
                    {
                        pos = j;
                        temp = i[j];
                    }
                }
                else {
                    if (i[pos] &lt; i[j])
                    {
                        pos = j;
                        temp = i[j];
                    }
                }
            }

            temp2 = i[pos];
            i[pos] = i[p];
            i[p] = temp2;
        }


    }
    }

};

int main()
{
    int d;


    inout x;
    x.read();
    cout&lt;&lt;"Press 1 to sort into ascending order"&lt;&lt;endl&lt;&lt;"Press any other key to sort into descending order"&lt;&lt;endl;
    cin&gt;&gt;d;
    x.sortData(d);  
    x.write();

}
</code></pre>
