IO operations for C + +

Source: Internet
Author: User

#include <iostream>
using namespace Std;
int main ()
{
Char name[20];
char gender;
int age;
cout << "Please enter your name, gender (m/f) and age:" <<endl;
CIN >> Name >> gender >> age;
cout << "Name:" <<name <<endl;
cout << "Sex:" <<gender <<endl;
cout << "Birthday:" <<2014-age<<endl;

}

[Email protected] c++]# g++ name.cc
[Email protected] c++]#./a.out
Please enter your name, gender (m/f) and age:
Zhang San M 22
Name: Zhang San
Sex:m
birthday:1992
[Email protected] c++]#


What if the age is less than 0?

{
        Char name[20];
        char gender;
        int age;
        cout << "Please enter your name, gender (m/f) and age:" <<endl;
        CIN >> name >> gender >> age;
        cout << "name:" <<name <<endl;
        cout << "Sex:" <<gender <<endl;
        if (age>=0)
                cout << "born Year: "<<2014-age<<endl;
        if (age <0)
        {
          &NBSP ;     cout << "Are you from the future??" "<<endl;
                cout << "born in" <<-age<< "years later! "<<endl;
       }
}

[Email protected] c++]#./a.out
Please enter your name, gender (m/f) and age:
Machine Cat M-10
Name: Doraemon
Sex:m
Are you from the future??
Born in 10!

IO operations for C + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.