|Oct 23, 2010, 10:26 PM||#1|
Problem with using strings in Xcode (C++)
First off, I am brand new to Xcode. I have been trying to learn how to program in C++ for a couple of days now.
Whenever I attempt to use the following code:
string name= "";
cout << "What is your name?\n";
cout << "\nHello " << name.c_str() << "\n";
I always get the following error message:
What is your name?(1345) malloc: *** error for object 0x100004220: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
I have looked around the internet and I have found nothing that has helped me. I found one article that told me how to set the break point, but that didn't work. If anybody knows about this please answer. All answers are appreciated.
|Oct 23, 2010, 11:57 PM||#2|
Are you sure you set up the project correctly?
I just tried it in SL on the command line and a command line cpp project and they worked.
How did you create your project?(and what version of XCode are you using?)
|Oct 24, 2010, 12:10 AM||#3|
This comes up all the time. Maybe something at the top of the forum is in order. It comes down to killing Preprocessor macros in the debug build settings.
Also, string knows what to do with <<, so no need to c_str. [CODE][/CODE] tags are fun for everyone.
Edit: Now there's something in the forum header. Change away if it's not clear.
Last edited by lee1210; Oct 24, 2010 at 12:45 AM.
|Oct 24, 2010, 12:26 AM||#4|
You didn't ask, but you may want to give up on learning C++ with Xcode.
Why? If you're going to use C++ on Windows, you should learn it on Windows. If you're going to program for the Mac, you'll want to use Objective-C (in general).
iMac 21.5", 3.06GHz, 4 GB, 2 TB HD.
iPod Touch 3G.
|Oct 24, 2010, 10:32 AM||#5|
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|Xcode problem with getting string||iDylanK||iPhone/iPad Programming||0||Jul 8, 2011 03:13 AM|
|How can I use the fstream library (C++) in Xcode?||MihaiBucataru||Mac Programming||9||Mar 5, 2011 09:23 AM|
|Problem with Xcode or Problem with this string of codes?||Xcode Beginner||OS X||5||May 6, 2010 03:12 PM|
|Problem with using NSTimer in another thread||antwerp||iPhone/iPad Programming||0||Oct 27, 2009 06:16 AM|
|system("pause"); in xcode (C programming)||darxun||Mac Programming||1||May 14, 2008 08:06 AM|
All times are GMT -5. The time now is 11:35 AM.