Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ronin Magus

Need some quick help

This topic is 5825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Yes, this is for a school assignment. But my question comprises only an insignificant part of the assignment, so I don''t feel bad at all about getting help with it.. I need to be able to input from a file that has been piped into my program (the assignment is not about reading from redirected files, it''s about finite state machines but just happens to use a redirected file for input.) Basically the file is just a single line and looks like this: 0010201 or something of the like. I need to read and use these characters one at a time using cin, and I am not allowed to buffer them into an array. My problem is that I am not well versed with standard input and since the amount of inputted numbers can vary, I don''t know how to check for end of the input. There''s no newline or anything after the last character, just the end of the file. I can''t check for EOF, because I have to read in from standard and can''t open a file. Any help?

Share this post


Link to post
Share on other sites
Advertisement
If you''re redirecting from a file, you can check for EOF.
Alternatively, you could check for the character being read being a ''\n''.

Share this post


Link to post
Share on other sites
Well, it doesn't seem to catch a '\n', which is what I've been trying. For example:


    
// get the first input symbol

cin >> c;

while(c != '\n')
{
// print the output of the current state

cout << out[currentstate];

// finite state machine stuff here ...


// get the next input symbol

cin >> c;
}


The program never exits the while loop, because cin ignores newlines.

[edited by - Ronin Magus on December 5, 2002 6:15:58 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!