Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Getting User Input after getting Input from a file

Reply
Thread Tools

Getting User Input after getting Input from a file

 
 
dei3cmix@uga.edu
Guest
Posts: n/a
 
      03-22-2006
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

 
Reply With Quote
 
 
 
 
Walter
Guest
Posts: n/a
 
      03-22-2006
Is there a way to redirect cin from stdio to file io in application?

 
Reply With Quote
 
 
 
 
Daniel T.
Guest
Posts: n/a
 
      03-23-2006
In article <(E-Mail Removed). com>,
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> 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


Try posting the real code instead of pseudocode.


--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
 
Reply With Quote
 
dei3cmix@uga.edu
Guest
Posts: n/a
 
      03-23-2006
I already figured it out. I will just use ifstreams to get the file
input and regular cin to get the input from the command line. I found
out there is no way to redirect a stream from a file back to the
command line in C++. Thanks everyone though.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting user input from user on a webpage? Adam Lee Ruby 4 06-10-2009 02:41 PM
upload file to server immed after user selects the file Steve Richter ASP .Net 1 05-25-2007 06:43 AM
trying to spawn a process (say an exe file) with different user crendentials than that of the current user but getting 1314 error ranju C++ 1 05-18-2007 02:35 AM
how to restrict user from input in <input type="file"> Tarkeshwar Javascript 2 04-17-2006 11:44 AM
How to keep input value in user controls after postback elain ASP .Net 1 11-21-2003 11:17 PM



Advertisments