Thread: Multiple inputs with cin

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    6

    Multiple inputs with cin

    #include <iostream>
    using namespace std;

    struct date
    {
    int month[2];
    int day[2];
    int year[4];
    char dummy[1];
    };

    int main()
    {
    date birthday;

    cout << "\nPlease enter your birthdate (mm/dd/yyyy): ";
    cin >> birthday.month >> birthday.dummy << birthday.day >> birthday.dummy << birthday.year;

    cout << "\n\nYour birthday is on "<< birthday.month << "/" << birthday.day << "/" << birthday.year;

    return 0;
    }



    im having problems with the cin statements. here is the error message im getting:

    error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'int [2]' (or there is no acceptable conversion)


    what am i doing wrong? the dummy[1] variable is to take in the "/" in the date format. i tried it without that. i just wont compile! please help!

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    int day[2] is an array, and there is no predefined way to read in a array.
    I think you got your struct date wrong, it should be:
    Code:
    struct date
    {
    int month;
    int day;
    int year;
    char dummy;
    };
    int month[2] will declare two month variables (an array), and I doubt that is what you want .

    I also noticed a << in your cin statement, perhaps it should be >> ?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    looking for the truth moemen ahmed's Avatar
    Join Date
    Feb 2002
    Location
    Egypt
    Posts
    161
    Code:
    #include <iostream>
    #include <conio.h>
    using namespace std; 
    
    struct date
    {
    int month[2];
    int day[2];
    int year[4];
    char dummy[1];
    };
    
    int main()
    {
    date birthday;
    
    cout << "\nPlease enter your birthdate (mm/dd/yyyy): ";
    cin >> *(birthday.month) >> *(birthday.dummy)>> *(birthday.day)>> *(birthday.dummy);
    cin >> *(birthday.year);
    
    cout << "\n\nYour birthday is on "<< *(birthday.month) << "/" << *(birthday.day )<< "/" << *(birthday.year);
    getche();
    return 0;
    }
    notice: you got 2 errors in your code

    1- the type mistake (as i think) << instead of >>
    2- u used the name of the arrays to assign value, while the name of any array is just a pointer to its first element. so you have to treat it as a pointer

    I hope this helps you
    Last edited by moemen ahmed; 02-16-2003 at 04:12 PM.
    Programming is a high logical enjoyable art for both programer and user !!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. checking inputs meets multiple conditions
    By 60beetle60 in forum C Programming
    Replies: 5
    Last Post: 04-19-2008, 08:25 AM
  2. multiple instances of cin
    By Chaplin27 in forum C++ Programming
    Replies: 4
    Last Post: 10-08-2004, 04:51 PM
  3. multiple inputs of multiple types
    By frontz in forum C Programming
    Replies: 8
    Last Post: 01-19-2004, 02:57 PM
  4. Multiple variable cin line
    By Dark Nemesis in forum C++ Programming
    Replies: 3
    Last Post: 08-02-2003, 10:57 PM
  5. Getting multiple inputs using cin
    By edk in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2001, 02:34 PM