proggR Posted February 2, 2009 Share Posted February 2, 2009 This should probably be in the Other Language section but maybe its broader than just c++ I have a text file that looks something like this: RPSRPRRPSSPRPRRPSPRPSPRPSSSP ...etc I'm trying to read it in and asign the value to a character. Its for a game of rock paper scissors and each letter corresponds to a play. However for some reason when I run it the first character seems to be a space, the second is a block (like when you use the symbol font in WordPad) and not until the third does it get to a letter. Then after that it reads more garbage and after another two or three times I get the second letter. The file is a plain text file, not rtf or any other kind of file and I have no spaces in the file. I'm going to just create a function to validate the input before assigning it to my character variable but can anyone fathom what is happening? Also, any help with the validation would be appreciated but I expect I'll find something before I get a response. Thanks in advance for any help. Quote Link to comment https://forums.phpfreaks.com/topic/143436-input-text-file-contains-spaces/ Share on other sites More sharing options...
Daniel0 Posted February 2, 2009 Share Posted February 2, 2009 Where did the file come from in the first place? Can't you just discard and move on to the next item if the current one is an invalid value? Quote Link to comment https://forums.phpfreaks.com/topic/143436-input-text-file-contains-spaces/#findComment-752380 Share on other sites More sharing options...
proggR Posted February 2, 2009 Author Share Posted February 2, 2009 I just opened notepad and typed it. I think I'm just going to have a function that only assigns the value of get() to the variable if its one of the three values. I just have to figure out how to pass a file stream as an object to a function :S Quote Link to comment https://forums.phpfreaks.com/topic/143436-input-text-file-contains-spaces/#findComment-752684 Share on other sites More sharing options...
corbin Posted February 2, 2009 Share Posted February 2, 2009 The same way you pass any object to a function: type function_name(class_name variable_name) { } Except I'm sure an fstream must be passed by reference (by a pointer), so it would look like this: type function_name(fstream *fs) { fs->someMethod(); } As for the three weird characters at the start of the file (it's from a file yes, or is it from cin or somewhere?), are you using UTF8 with BOM by any chance? Quote Link to comment https://forums.phpfreaks.com/topic/143436-input-text-file-contains-spaces/#findComment-753027 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.