Jump to content

Input text file contains spaces?


proggR

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.