Untitled(58970) malloc: *** error for object 0x1000041c0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Program received signal: “SIGABRT”.

The strange thing is that the program works normally in both Terminal.app and gdb, so I don't know what the Debugger Console in Xcode is doing to produce the crash.

12-25-2009

jeffcobb

cin and string objects

I didn't think the STL worked like that (getline() is looking for an array):

Code:

// istream getline
#include <iostream>
using namespace std;

int main () {
char name[256], title[256];

cout << "Enter your name: ";
cin.getline (name,256);

cout << "Enter your favourite movie: ";
cin.getline (title,256);

cout << name << "'s favourite movie is " << title;

return 0;
}

12-25-2009

laserlight

Quote:

Originally Posted by jeffcobb

I didn't think the STL worked like that (getline() is looking for an array):

Well, now you know that there is also a free function version that works for std::basic_string :)

12-25-2009

Dino

Jeff, Memloop and I are using the global getline that is part of the string class. You are using the stream flavor.

12-25-2009

jeffcobb

Quote:

Originally Posted by laserlight

Well, now you know that there is also a free function version that works for std::basic_string :)

See? I learn something new everyday. Most of my C++ know-how is more than 15 years old...question: at one point it was common knowledge that you did not mix malloc/free and new/delete....but now you say there is a C++ version of free() that works with strings...so is the "no-mixing" rule still valid?

Happy Holidays all..

J.

12-25-2009

Dino

Laserlight might have meant free, as in "no charge - you get it for free".

12-26-2009

adeyblue

Quote:

Originally Posted by Dino

Laserlight might have meant free, as in "no charge - you get it for free".