| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
cin.get will not work
Please tell me what I am doing wrong.
I have written this code Code:
#include "Source.h"
void initative()
{
int I;
int y = 1;
int x = 1;
char YesNo;
char Fall;
char name[25];
system("cls");
cout << "INITATIVE TEST\n\n\n"
<< "Some stuff about initative tests.\n"
<< "Please enter your characters name......" << endl;
cin.get( name, 25);
cout << "So " << name << " needs an initative test.\n"
<< "Is this a test to see if " << name << " will fall off an edge? (Y/N). " << endl;
but when the programe gets to the cin.get bit of the program it just ignores it like it isnt there and just gives me 25 white space characters. What am I missing to get a user to input the info needed? Thanks in advance Ad. |
|
#2
|
|||
|
|||
|
well first of all, your initialize() function doesn't have a closing brace.
I don't know what is in Source.h, but the following program works fine in Dev-C++ 4.9.9.2 on Windows: Code:
//#include "Source.h"
#include <iostream>
using namespace std;
//void initative()
int main()
{
int I;
int y = 1;
int x = 1;
char YesNo;
char Fall;
char name[25];
system("cls");
cout << "INITATIVE TEST\n\n\n"
<< "Some stuff about initative tests.\n"
<< "Please enter your characters name......" << endl;
cin.get( name, 25);
cout << "So " << name << " needs an initative test.\n"
<< "Is this a test to see if " << name << " will fall off an edge? (Y/N). " << endl;
return 0;
}
|
|
#3
|
|||
|
|||
|
Thanks for the help. The code is only the first part of the program that is called after main hence the missing brace and the name of the function.
After a bit more investigation what is happening is that if I rename this function to main and compile it without the rest of the program then it will prompt for the name successfully. However when compiled with the rest of the program it just skips over the get.cin command and inserts 25 white spaces. In Source.h I have the following. #include <iostream.h> #include <stdlib.h> #include <conio.h> #include <stdio.h> #include <ctype.h> as well as all my function declerations void main(); void leadership(); void initative(); void fallen(); I am compiling it with MS Visual C++ Ver 6. Any idea why it would be doing this? Again thanks for the help. |
|
#4
|
||||
|
||||
|
Quote:
try placing the following line of just before the cin.get() Code:
fseek(stdin,0L,SEEK_END) it's possible you have a newline or something in the buffer that needs to be flushed out...
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips. ![]() |
|
#5
|
|||
|
|||
|
Thanks for the help but it is still skipping the cin.get command.
|
|
#6
|
||||
|
||||
|
I see you've edited your code in your origonal post.... the way it stands right now, does it not work? Because if it doesn't, you're compiler must be bugged or something, beause that's a darned simple, straight-forward program, I can't think of anything that would cause it to not work....
try compiling a program with nothing but a cin.get() and see if it works then, then you can see if it's a general cin.get() problem or just one specific to your code.... |
|
#7
|
|||
|
|||
|
I have tried compiling the program with just using the cin.get command and I have also inserted it into the main() function in this program and it works fine. When it stops working is when I call another function.
I am calling the other functions using a switch statement. Any more ideas or could it just be my compiler ? |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > cin.get will not work |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|