할당되지 않은 해제하고 다음과 같은 오류와 함께 실패되고 : 파일 input.txt을의C++ 과부하 >> 나는 다음과 같은 코드를 시도하고
malloc: *** error for object 0x10000d8c0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Program received signal: “SIGABRT”.
다음
있습니다 내용 : 그것은 전체가 권한 및 파일이 디버거에서 성공적으로 열립니다. 도와주세요.
Jacob Anderson
Michael Thomson
Joshua Smith
Mathew Matheis
Ethan Evans
Emily Drake
Emma Patterson
Madison McPhee
Hannah Briens
Ashley Schmidt
.
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <list>
#include <fstream>
#include <string>
#include <stdio.h>
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& operator << (ostream& os, DataType myData) {
os<<myData.firstname<< " "<<myData.lastname;
return os;
}
bool operator < (DataType lhs, DataType rhs) {
if (lhs.firstname < rhs.firstname)
return true;
return false;
}
int main() {
ifstream studentFile ("input.txt"); // Student file
list <DataType> students; // Students
DataType currStudent; // One Student (has firstname,lastname)
if (! studentFile.is_open())
{
return -1;
}
while (studentFile >> currStudent.firstname >> currStudent.lastname) {
students.push_back(currStudent);
}
list<DataType>::iterator i = students.begin();
while (i != students.end()) {
cout << *i << endl ;
++i;
}
}
이 문제인가? : http://stackoverflow.com/questions/2234557/c-using-getline-prints-pointer-being-freed-was-not-allocated-in-xcode – ergosys