Xcode C++ getline() fix

Discussion in 'iOS Development' started by flyingguitar, Mar 4, 2010.

  1. flyingguitar

    flyingguitar Active Member

    Joined:
    May 14, 2008
    Messages:
    1,860
    Likes Received:
    11
    Device:
    iPhone 6
    Sorry this really doesn't have anything to do with iPhone development, but I'm sure C++ devs who use Xcode will appreciate this...

    I found a bug in Xcode today, it doesn't take the getline() function.

    normally it would look something like this:

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main() {
    	string mystring;
    	getline(cin, mystring);
    	cout << mystring;
    	return 0;
    }
    just for a simple example, but when normally compiled it will look similar to this:

    Code:
    test
    TEMP(3612) malloc: *** error for object 0x1000041c0: pointer being freed was not allocated
    *** set a breakpoint in malloc_error_break to debug
    Program received signal:  “SIGABRT”.
    sharedlibrary apply-load-rules all
    (gdb) 
    so I have this header file that will fix that, all you have to do is unzip it then add it to your project's directory and add
    Code:
    #include "getlinefix.h"
    to the top of your code, it MUST be the first header file you include, so the new code would look like this:

    Code:
    #include "getlinefix.h"
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main() {
    	string mystring;
    	getline(cin, mystring);
    	cout << mystring;
    	return 0;
    }
    and the new output:

    Code:
    test
    test
    appears to work fine

    Please Register or Log in to view images

    Attached Files:

  2. nicolamontini

    nicolamontini New Member

    Joined:
    Jul 13, 2011
    Messages:
    1
    Likes Received:
    0
    Thanks

    Very helpful, thanks a lot!!! :-D

Share This Page