Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ overload >> for ifstream on mac pointer being freed was not allocated
    primarykey
    data
    text
    <p>I am trying the following code and it fails with the following error: </p> <pre><code>malloc: *** error for object 0x10000d8c0: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Program received signal: “SIGABRT”. </code></pre> <p>Here are contents of file input.txt : It has full permissions and file is successfully opened in debugger. Please help.</p> <pre><code>Jacob Anderson Michael Thomson Joshua Smith Mathew Matheis Ethan Evans Emily Drake Emma Patterson Madison McPhee Hannah Briens Ashley Schmidt </code></pre> <p>.</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;functional&gt; #include &lt;algorithm&gt; #include &lt;list&gt; #include &lt;fstream&gt; #include &lt;string&gt; #include &lt;stdio.h&gt; using namespace std; struct DataType { string lastname; // (Key) Student's Last Name string firstname; // Student's First Name string getKey () const { return lastname; } // Returns the key field }; ostream&amp; operator &lt;&lt; (ostream&amp; os, DataType myData) { os&lt;&lt;myData.firstname&lt;&lt; " "&lt;&lt;myData.lastname; return os; } bool operator &lt; (DataType lhs, DataType rhs) { if (lhs.firstname &lt; rhs.firstname) return true; return false; } int main() { ifstream studentFile ("input.txt"); // Student file list &lt;DataType&gt; students; // Students DataType currStudent; // One Student (has firstname,lastname) if (! studentFile.is_open()) { return -1; } while (studentFile &gt;&gt; currStudent.firstname &gt;&gt; currStudent.lastname) { students.push_back(currStudent); } list&lt;DataType&gt;::iterator i = students.begin(); while (i != students.end()) { cout &lt;&lt; *i &lt;&lt; endl ; ++i; } } </code></pre>
    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.
 

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