Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 23, 2010, 09:26 PM   #1
Fx1k
macrumors newbie
 
Join Date: Oct 2010
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:

#include <iostream>
#include <string>


int main(void)
{
using std::cin;
using std::cout;
using std::string;
string name= "";

cout << "What is your name?\n";
cin>> name;
cout << "\nHello " << name.c_str() << "\n";

return 0;
}

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
Abort trap
logout

[Process completed]

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.
Fx1k is offline   0 Reply With Quote
Old Oct 23, 2010, 10:57 PM   #2
foidulus
macrumors 6502a
 
Join Date: Jan 2007
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?)
foidulus is offline   0 Reply With Quote
Old Oct 23, 2010, 11:10 PM   #3
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
http://forums.macrumors.com/showthread.php?t=1014767

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.

-Lee

Edit: Now there's something in the forum header. Change away if it's not clear.

Last edited by lee1210; Oct 23, 2010 at 11:45 PM.
lee1210 is offline   0 Reply With Quote
Old Oct 23, 2010, 11:26 PM   #4
PatrickCocoa
macrumors 6502a
 
Join Date: Dec 2008
Switch gears

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.
PatrickCocoa is offline   0 Reply With Quote
Old Oct 24, 2010, 09:32 AM   #5
subsonix
macrumors 68030
 
Join Date: Feb 2008
Quote:
Originally Posted by PatrickCocoa View Post
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).
MS Windows has nothing to do with this. C++ is an open standard language and there is no reason you can not do standard C++ development on a mac any more than, Ruby, Python, Perl etc. If the aim is to make native os X GUI applications, I agree Cocoa and obj-c is the natural choice, but nothing is being said about that here at all.
subsonix is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
XCode 5 DP and Java Problem aquethys Mac Programming 0 Aug 28, 2013 09:59 PM
Xcode OpenGL Ram Problem jmfel1926 Mac Programming 5 Aug 21, 2013 06:06 PM
Problem with XCode 4 .6 Senor Cuete Mac Programming 7 Feb 11, 2013 09:15 AM
After updating XCode, output terminal problem iMacFarlane Mac Programming 9 Oct 3, 2012 11:29 PM
Xcode problem JamesP. Mac Applications and Mac App Store 0 Jul 4, 2012 10:41 AM

Forum Jump

All times are GMT -5. The time now is 10:38 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC