PDA

View Full Version : Help using XCode to learn C++




Jalaska13
Mar 21, 2009, 04:04 PM
Hi guys!
I've been trying to teach myself C++ from a book that is written for PC users (most are). I simply skipped the steps it says about installing the compiler that comes with the book, and figured i'd use XCode. After all, C++ is the same, no matter the platform. However, i'm having a bit of difficulty. When I try to type in the code examples they give, and then compile and run them, all the "build" and "run" commands are greyed out in the pulldown menus. All i have is a simple C++ file (.cpp). No headers, no make files, nothing. Just that little bit of code. What am I doing wrong?
here's the code:

#include <iostream>
using namespace std;

int main() {
cout << "Never fear, C++ is here!";
return 0;
}



lee1210
Mar 21, 2009, 04:11 PM
Choose File->New Project
Under Command Line Utility, choose C++ tool

Now you can enter your code.

This will set up the environment for the sort of thing you want to do, so it knows what compiler to use, etc.

-Lee

Jalaska13
Mar 21, 2009, 04:37 PM
ahhh thanks!

Trinimini
Oct 19, 2009, 10:46 AM
I've just recently started learning C++ on XCode myself and have attempted to make a simple program. My code is:

#include <iostream>
#include <string>
using namespace std ;

int main (void)
{
string name ;

cout << "Enter you full name. " ;
getline(cin,name);

cout << "Hello, " << name << endl ;

return 0 ;
}

Before it asks me to enter my name, I see all this stuff in the console window:


The Debugger has exited with status 0.
[Session started at 2009-10-19 11:44:11 -0400.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1346) (Fri Sep 18 20:40:51 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
Loading program into debugger…
Program loaded.
run
[Switching to process 1213]
Running…

I was wondering if there's a way to get rid of that ^?

When I enter my name, I get this message:

MyProgram(1213) malloc: *** error for object 0x1000041e0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Program received signal: “SIGABRT”.
sharedlibrary apply-load-rules all

Clearly there's an error and I was wondering what is wrong with my code?

gnasher729
Oct 19, 2009, 11:08 AM
When I enter my name, I get this message:

MyProgram(1213) malloc: *** error for object 0x1000041e0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Program received signal: “SIGABRT”.
sharedlibrary apply-load-rules all

Clearly there's an error and I was wondering what is wrong with my code?

Well, it gives you a bloody big hint what to do if you want to debug your code.

Trinimini
Oct 19, 2009, 01:27 PM
considering the fact that i'm new to this and i got this code from a website to test out xcode how am i to know what that jibberish means?

gnasher729
Oct 19, 2009, 05:43 PM
considering the fact that i'm new to this and i got this code from a website to test out xcode how am i to know what that jibberish means?

*** set a breakpoint in malloc_error_break to debug

Trinimini
Oct 19, 2009, 08:52 PM
I tried googling '*** set a breakpoint in malloc_error_break to debug' and one result told me to hit 'alt+cmd+B' and then near the blue cube icon to input 'malloc_error_break' i tried that and it didn't work.

kny3twalker
Oct 26, 2009, 01:59 AM
cin >> name;

instead of getline stuff you have

I registered just to reply to this. I am not sure why he is trying to explain much more advanced debugging or whatever rather than just point out the obvious mistake.

malloc is memory allocation stuff. I am still a student so I cannot really tell you much more.

Oh and you do not need void inside of int main()