D
dei3cmix
Hey, I am having a problem with a program I am working on. Basically,
the first part of the program gets input from a file using cin.getline.
Then the second part, (still in the same main as the first part) needs
to get input from the user, and I want to do this with cin.getline
also. The problem I am getting, is when I run the program, the text if
read in from the file correctly, but it seems to just skip over the
cin.getline when I want to get input from the user. I think this is
having something to do with the cin.getline still trying to read the
file, and getting the EOF and returning null, instead of pausing for
the user input. I want it to stop trying to get input from the file,
and get input from the user on the command line. Any help on how to fix
this? Thanks in advance.
My program: (in pseudocode)
int main ()
{
//getting text from file
while ( cin.getline ( text [], size, '\n' ) )
{
//processing text from file
}
//getting input from user
bool b = false; //if 1 is entered by user, b is set to true and
program ends
while ( !b )
{
cin.getline ( userinput [], usize, '\n' );
//check to see if user entered 1
if (user didnt enter 1)
{
process user input
}
else
b = true;
}
return 0;
}//end main
the first part of the program gets input from a file using cin.getline.
Then the second part, (still in the same main as the first part) needs
to get input from the user, and I want to do this with cin.getline
also. The problem I am getting, is when I run the program, the text if
read in from the file correctly, but it seems to just skip over the
cin.getline when I want to get input from the user. I think this is
having something to do with the cin.getline still trying to read the
file, and getting the EOF and returning null, instead of pausing for
the user input. I want it to stop trying to get input from the file,
and get input from the user on the command line. Any help on how to fix
this? Thanks in advance.
My program: (in pseudocode)
int main ()
{
//getting text from file
while ( cin.getline ( text [], size, '\n' ) )
{
//processing text from file
}
//getting input from user
bool b = false; //if 1 is entered by user, b is set to true and
program ends
while ( !b )
{
cin.getline ( userinput [], usize, '\n' );
//check to see if user entered 1
if (user didnt enter 1)
{
process user input
}
else
b = true;
}
return 0;
}//end main