Parsing date and outputting as date month and year
Hi,
I'm very new to c++ and have the following small program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <iostream>
using namespace std;
int main()
{
string dob;
cout << "Type your name of birth. Format: ddmmyyyy" << endl;
cin >> dob;
cout << "month of birth: " + dob[2] + dob[3] << endl;
cout << "date of birth: " + dob[0] + dob[1] << endl;
cout << "year of birth: " + dob[4] + dob[5] + dob[6] + dob[7] << endl;
}
|
But when I give something like 19031991 it doesn't work, and with that particular input just outputs "zPLR" :S why is this?...
Thanks,
Jarob22
dob[2]
is a char.
You cannot use the +
operator to concatenate "month of birth: " and a char.
You don't actually need to concatenate them; just output the char separately with the <<
operator.
Woo, ok thanks that works :)
Topic archived. No new replies allowed.