Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bobber205

macrumors 68020
Original poster
Nov 15, 2005
2,182
1
Oregon
Below is what I use in Visual studio. Using getline I can have names entered that have spaces etc. If there is a space and I use cin, I get an infinite loop. (other code doesn't matter, it's just a function call.

All variables have been declared ok. What do I use insteasd of clear buffer etc on OS X?

Code:
void GetString(char* str) {

    cout << "Please Enter a String: " << endl;
    cin >> str;
   // cin.ignore(cin.rdbuf()->in_avail());
    //cin.getline(str, 100);
   // cin.clear();
    //cin.ignore(cin.rdbuf ()->in_avail());

    cout << endl;

}
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Not sure I understand exactly, but getline works fine for reading spaces:

Code:
void GetString(char* str)
{
	cout << "Please Enter a String: " << endl;
	cin.getline(str, 100);
	cout << endl;
}
 

bobber205

macrumors 68020
Original poster
Nov 15, 2005
2,182
1
Oregon
But when I try to run that function, it skips completely over my whole function call. The line "Enter your string" is printed, but I am never prompted to enter anything. It skips right along to printing the menu again. :(
 

LtRammstein

macrumors 6502a
Jun 20, 2006
570
0
Denver, CO
Hmmm... If I remember correctly the input needs to be put to a variable.

Just using cin or it's subfunctions doesn't do anything because it has nowhere to put it. Or at least that's what I'm getting from the code.

Steve
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.