Xcode entering input error help please

When i run Xcode 4.5.2 on Lion and i need to enter some input (ex. cin.getline(array,10)), i need to press enter two times to keep going.

Here is the code:


player1 and palindrom are arrays of char

User uploaded file

and here is the output:

User uploaded file

I enter Juan in player1 then i press [Enter] and i need to press another [Enter] if i want the prgram to continue

and when i enter the palindrom is not stored in the array, instead the second [Enter] is stored on the palindrom array.


Help please

i dont know what to do i have looked on the internet but i havent found anything to solve this problem......

Xcode 4.5.2-OTHER, Mac OS X (10.7.5), input error

Posted on Nov 11, 2012 10:04 PM

Reply
4 replies

Nov 13, 2012 7:17 AM in response to quiban92

You are mixing up two different ways of getting user input.


1. getline -- a standard <stdio> function which reads user input and a return;

2. cin -- a C++ <iostream> function which reads user input and a return.


See http://crasseux.com/books/ctutorial/getline.html and http://www.htmlhelpcentral.com/messageboard/showthread.php?4359-C-Tutorial-1-cou t-cin for the proper way to use either one of them; you cannot use both in the same command.


quiban92 wrote:


i dont know what to do i have looked on the internet but i havent found anything to solve this problem......


Those two links were the very first hits on a search for "getline tutorial" and "cin tutorial".

Nov 13, 2012 6:14 PM in response to Jongware

I managed to solved the problem switching the cin.getline with simple cin.


but i still couldnt find out why does cin.getline asks for double enter on Xcode i wrote the same code on Scite and it doesnt behave the same.....


Also i dont undestand what you mean by mixing up two different ways of getting user input.


im taking computer science and the told us that there are different ways to get input from the user and a few that we often use are cin , cin.get , cin.getline.


Nov 14, 2012 3:30 AM in response to quiban92

Apologies about my 'getline' mishap -- it's a valid cin function after all.


Some further research led me to this: cin.getline(dest, count) reads up to count characters and ignores everything that follows. Perhaps your NAME_LENGTH value is 4? In that case, cin.getline is done right after you entered "Juan", and the hard return is left dangling for the next command. (See http://www.cplusplus.com/reference/iostream/istream/getline/ for a better description.)


I found it's commonly suggested to add an 'ignore' right after each getline, to prevent any unwanted characters in the next input line.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Xcode entering input error help please

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.