Extracting numbers

Im having some trouble with a certain code.

What im trying to do is ask the user to enter 8 numbers
and then i want to extract the first four numbers, followed by the next two numbers and finally the last two numbers.
so for example,
user enters 12345678
i display it as
any help would be appreciated.thanks.
Well, assuming that there is no numerics involved, simply make it a string. Then just parse through, where string[0-3] will be the first four numbers.
Just read in each character and output them again.

Here is an excessively obfuscated example that I made for fun:
char ch;
for(int i = 0; i < 8 && std::cin >> ch && std::cout << ch && ((i == 3 || i == 5) && std::cout << std::endl || std::cout << std::flush); ++i){}
(I don't recommend using it as a reference)
This is absolutely fantastic! thanks a lot.

just 1 simple question.
how can i cout and say for example
year is: 1234
month is: 56
day is: 78

i dont know how to enter it within the data you have given me.
Can you post the program you have? I should be simple adjustments. (Remember, my program is the hard way to do it)
I'm a little bit confused on the month is 56 and day is 78? Also you will probably have to read it into 1 string then parse it or read each digit into a character then output the first 4 for the year , 5-6 as month , and 7-8 as day.
Just use substrings to parse the string.
Read the number in as a string,

string input = "balloon";
string parsed;

parsed = input.substr(0,4); //this starts at input[0] and continues to input[4];

cout << parsed << endl;

output will be 'ball'.

The rest you can figure out.
Topic archived. No new replies allowed.