C++ input and strings

Hello everyone I am working on a project for my CS class and I am stuck on part of it. I am new to C++ so it's been hard at times.

I have a line of data in a file:

63f7hj-9 22spaces L Is this correct 22spaces L Is this correct

-In the phrase "63f7hj-9" I have to save the 63 as in integer and discard everything else up to and including the 9
-I need to save the phrase "22spaces" as a string
-I need to save the L as a character
-And lastly I need to save the phrase "Is this correct" as another string

I hope someone is able to help and thank you for your time

Is it the exact same line of data every time? As in, always
63f7hj-9 22spaces L Is this correct 22spaces L Is this correct
or could the values be different? If it could change, WHAT in it could change and what will always be the same?
I only have one line of data in the file. The project is to take an ascii number and convert that to a character and use that character to fill in how ever many spacers the data file says.

Heres an example:

63f7hj-9 22spaces L Is this correct 22spaces L Is this correct

The 63 in the beginning is the ascii number for ?. I have to fit the entire output in 22 spaces. And the phrase "Is this correct" is at the end.

My output would look like:

???????Is this correct

I have to figure out how to only get the 63 from the phrase "63f7hj-9"

I ask because if the line is always the same, you don't need to read the numbers. You already know the value is 63.
int x = 63; Done.

If the line can be different each time, then you need to identify the acceptable format. Will the line's first two characters always, ALWAYS be two digits representing a single ASCII character?


The purpose of assignments like this are to verify/enforce understanding of formatted input operations.

That's the kind of thing g that looks like this:

cin >> my_int >> my_string;

Except, instead of cin you will be using an ifstream object.

The trip K is to play around with it until it makes sense. Good luck!
Topic archived. No new replies allowed.