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 Dec 8, 2012, 04:04 AM   #1
Adrian00
macrumors newbie
 
Join Date: Dec 2012
Xcode 4.5.2 - Execution stops after CIN input

Hello,

I am very new to programming, especially in C++ so I am sorry if I suck at describing the problem.

I am currently trying to run a programme to just simply input a value and output the value again.

Quote:
#include <iostream>
using namespace std;

int main()
{

int length;

cout << "Please enter length: ";
cin >> length;

cout << length;



return 0;
}
However, when I run the programme it stops after I input the value for CIN and never gives me any output.

I've researched on google and there seems to be a problem with the preprocessors of the debugger in earlier versions. However I couldn't find any of these settings in my Xcode.

The problem seems similar to this, however the solutions don't resolve my problem and I also don't have any of the macros (or at least can't find them).


Does somebody know what to do here?

Lastly, please try and explain it step by step, so that I can follow it. :-)
Adrian00 is offline   0 Reply With Quote
Old Dec 8, 2012, 06:48 AM   #2
millerj123
macrumors 6502a
 
Join Date: Mar 2008
I can confirm that the code works as written although it might want an endl:

$ g++ mactest.c -o mactest
$ ./mactest
Please enter length: 45
45$ ./mactest
Please enter length: 12
12$
millerj123 is online now   0 Reply With Quote
Old Dec 8, 2012, 12:44 PM   #3
Adrian00
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
Are you using the newest version of Xcode?

And what does your reply mean, I don't understand what you did there.
Adrian00 is offline   0 Reply With Quote
Old Dec 8, 2012, 01:02 PM   #4
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
Instead of using Xcode he compiled and ran your code within the Terminal from the Command Line Interface, also known as the CLI.

Terminal.app can be found in /Applications/Utilities

In order to follow the example above lets assume the existence of a folder named 'FunStuff' on your Desktop that contains the source file 'mactest.c'.

First issue the command -

cd ~/Desktop/FunStuff

from the CLI.

This will set the current working directory to be within the specified directory. You can now reproduce his result following the commands issued in his example.

Have fun!!!

Last edited by lloyddean; Dec 8, 2012 at 06:48 PM.
lloyddean is offline   0 Reply With Quote
Old Dec 8, 2012, 01:09 PM   #5
Adrian00
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
Okay thank you very much.

But still no solution to the problem with Xcode?? :-(
Adrian00 is offline   0 Reply With Quote
Old Dec 8, 2012, 01:24 PM   #6
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
Deja Vu

At the top right of the window above the "source" pane is a collection of buttons. One of which is called "View". Select the center button. A "debug" pane should appear below your projects source.

EDIT:

The resulting view, below the source view, should be split into multiple view panels one of which should be "Console" output and input. If the console subview is not showing click on the middle of the three grouped buttons to the right of the "Clear" button and it should appear. This is where you see you programs output and where you type your responses.

Last edited by lloyddean; Dec 8, 2012 at 06:55 PM.
lloyddean is offline   0 Reply With Quote
Old Dec 9, 2012, 06:57 AM   #7
Adrian00
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
Mh, I have these windows and I am entering the values into 'All Output'. However the problem is still the same that I enter something and then the programme stops.

I just noticed something though. After compiling the build it says the name of my project between the source and the debug pane.
If I then enter the input it changes to 'No Selection'. Maybe that has something to do with the problem. I can't select anything after I enter an input there.

Thank you for all the help so far.

Last edited by Adrian00; Dec 9, 2012 at 07:25 AM.
Adrian00 is offline   0 Reply With Quote
Old Dec 9, 2012, 10:44 AM   #8
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
DO you have an extended keyboard with a numeric keypad?
lloyddean is offline   0 Reply With Quote
Old Dec 9, 2012, 11:20 AM   #9
Adrian00
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
Yes I do.

I saw where you are probably going with this and tested using my normal laptop integrated keyboard and suddenly it works.

What is the issue though with my external numerical keyboard and how do I fix it?
Adrian00 is offline   0 Reply With Quote
Old Dec 9, 2012, 11:37 AM   #10
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
My thought was you're hitting the "enter" key on the numeric keyboard instead of the "return" key.
lloyddean is offline   0 Reply With Quote
Old Dec 10, 2012, 12:48 PM   #11
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
It'd be polite if you could tell us if the "problem" has been taken care of.
lloyddean is offline   0 Reply With Quote
Old Dec 10, 2012, 04:40 PM   #12
Adrian00
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
Yes sorry, I just thought somebody might have an answer still.

The problem is solved and if I knew how I would mark this thread as solved.

Thank you so much everyone for helping me.
Adrian00 is offline   0 Reply With Quote
Old Dec 10, 2012, 05:50 PM   #13
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
Confusing response.

If it is solved please note the solution here.
lloyddean is offline   0 Reply With Quote
Old Dec 11, 2012, 02:35 AM   #14
Adrian00
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
I am not sure of the solution.

When you said whether I was using an external keyboard, I tried using the internal one, and voila, suddenly it worked.

I haven't changed any settings, other than restarting the system.
Adrian00 is offline   0 Reply With Quote
Old Dec 11, 2012, 09:01 AM   #15
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
So you're running a Macbook/Macbook Pro with who's external keyboard?
lloyddean 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 C input Creck Mac Programming 3 Sep 23, 2012 04:31 AM
Step by step execution in xcode? hajira iPhone/iPad Programming 2 Aug 21, 2012 05:47 AM
Input/Output with files in XCode crisro996 Mac Programming 2 Jul 21, 2012 12:20 PM
Code stops running in Xcode if input stream is long skatedate22 Mac Programming 6 Jul 10, 2012 03:44 AM

Forum Jump

All times are GMT -5. The time now is 09:20 AM.

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

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