C++ Regarding cin.ignore()
<p>i would hope someone can modify my code as its so buggy. sometime its work, sometime it dont..</p>

<p>so let me explain more.. Text file data is as below</p>

<pre><code>Line3D, [70, -120, -3], [-29, 1, 268]
Line3D, [25, -69, -33], [-2, -41, 58]
</code></pre>

<p>To read the above line.. i use the following</p>

<pre><code>char buffer[30];

cout &lt;&lt; "Please enter filename: ";
cin.ignore();
getline(cin,filename);

readFile.open(filename.c_str());

//if successfully open
if(readFile.is_open())
{
//record counter set to 0
numberOfRecords = 0;

while(readFile.good())
{
//input stream get line by line
readFile.getline(buffer,20,',');


if(strstr(buffer,"Point3D"))
{
Point3D point3d_tmp;
readFile&gt;&gt;point3d_tmp;

// and so on...
</code></pre>

<p>Then i did a overload on the ifstream for Line3d </p>

<pre><code>ifstream&amp; operator&gt;&gt;(ifstream &amp;input,Line3D &amp;line3d)
{
int x1,y1,z1,x2,y2,z2;

//get x1
input.ignore(2);
input&gt;&gt;x1;

//get y1
input.ignore();
input&gt;&gt;y1;

//get z1
input.ignore();
input&gt;&gt;z1;

//get x2
input.ignore(4);
input&gt;&gt;x2;

//get y2
input.ignore();
input&gt;&gt;y2;

//get z2
input.ignore();
input&gt;&gt;z2;
input.ignore(2);

Point3D pt1(x1,y1,z1);
Point3D pt2(x2,y2,z2);

line3d.setPt1(pt1);
line3d.setPt2(pt2);

line3d.setLength();
}
</code></pre>

<p>But the issue is the record work sometime and sometime it dont.. what i mean is if at this point</p>

<pre><code>//i add a cout
cout &lt;&lt; x1 &lt;&lt; y1 &lt;&lt; z1;
cout &lt;&lt; x2 &lt;&lt; y2 &lt;&lt; z2;

//its works!
Point3D pt1(x1,y1,z1);
Point3D pt2(x2,y2,z2);

line3d.setPt1(pt1);
line3d.setPt2(pt2);

line3d.setLength();
</code></pre>

<p>but if i take away the cout it dont work. how do i change my cin.ignore() so the data can be handle properly , consider number range is -999 to 999</p>
