Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ InStream Overload Issue
    primarykey
    data
    text
    <p>below is my code</p> <pre><code>ifstream&amp; operator&gt;&gt;(ifstream &amp;input,Line3D &amp;line3d) { int x1,y1,z1,x2,y2,z2; x1=0; y1=0; z1=0; x2=0; y2=0; z2=0; //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); //cout &lt;&lt; x1 &lt;&lt; "," &lt;&lt; y1 &lt;&lt; "," &lt;&lt; z1 &lt;&lt; "," &lt;&lt;endl; //cout &lt;&lt; x2 &lt;&lt; "," &lt;&lt; y2 &lt;&lt; "," &lt;&lt; z2 &lt;&lt; "," &lt;&lt;endl; Point3D pt1(x1,y1,z1); Point3D pt2(x2,y2,z2); line3d.setPt1(pt1); line3d.setPt2(pt2); line3d.setLength(); } </code></pre> <p>There this weird issue, if i comment my cout , the 2 cout above. My code will not work, but if i uncomment it, the code will work.. heres the terminal output..</p> <pre><code>Please enter your choice: 1 Please enter filename: messy.txt 10 records read in successfully! Going back to main menu ... </code></pre> <p>But if i uncomment cout...</p> <p>Please enter your choice: 1</p> <pre><code>Please enter filename: file.txt 7,12,3, -9,13,68, 7,-12,3, 9,13,68, 70,-120,-3, -29,1,268, 25,-69,-33, -2,-41,58, 9 records read in successfully! Going back to main menu ... </code></pre> <p>9 Records is the correct one. but why a cout will solve my code issue. while i thought cout just print to terminal. what did i do wrong here .</p> <p>This is the text file content</p> <pre><code>Point2D, [3, 2] Line3D, [7, 12, 3], [-9, 13, 68] Point3D, [1, 3, 8] Line2D, [5, 7], [3, 8] Point2D, [3, 2] Line3D, [7, -12, 3], [9, 13, 68] Point3D, [6, 9, 5] Point2D, [2, 2] Line3D, [70, -120, -3], [-29, 1, 268] Line3D, [25, -69, -33], [-2, -41, 58] Point3D, [6, 9, -50] </code></pre> <p>The correct response i want from terminal is </p> <pre><code>Correct output: 9 records read in successfully Reason: as 10 means the value fail to record to vector. and duplicate is not removed. </code></pre> <p>Thanks for all guide, what should i do to maintain the correct output yet remove away the cout..</p> <p>More of my code on main.cpp:</p> <pre><code>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,25,','); Line3D line3d_tmp; readFile&gt;&gt;line3d_tmp; done=true; //some for loop to check for duplication //done will be false if doesnt work if(done==true) { line3d.push_back(line3d_tmp); } </code></pre> <p>So you see if the value is push_back into my vector, the duplicate record will be remove, as i purposely put 2 records of same value. The issue is if i use the 2 cout line . The record is shown as 9 (correct as there 1 line of duplicate) and on second run to input same file. 0 records is being read..</p> <p>But if i comment away my cout, on second run, it read 4 RECORDS again. The first run was 10 records..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload