Why am I getting this error?

This is a discussion on Why am I getting this error? within the C++ Programming forums, part of the General Programming Boards category; ERROR: error C2679: binary '>>' : no operator defined which takes a right-hand operand of type '' (or there is ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    27

    Question Why am I getting this error?

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

    at cin

    Code:
    #include <iostream>
    #include <cstdlib>
    #include <iomanip>
    using namespace std;
    int main (void)
    {
    
    //declare arrays
    int Length[20];
    int Weight[20];
    string Species[20];
    
    //declare
    int l=0, w=0, s=0;
    
    int aveweight=0;
    
    int numberFish=0;
    
    
    cout<<"Enter number of fish:"<<endl;
    cin>>numberFish>>endl;

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >cin>>numberFish>>endl;
    endl isn't defined for istreams.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    27

    I am still getting the same error in this spot

    Code:
    //loop to read in species
    for (s=0;s<numberFish;s++)
    {
    	cout<<"Enter species of fish:"<<endl;
    	cin>>Species[s];

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    is there a closing ; to the for loop?

  5. #5
    Registered User
    Join Date
    Aug 2002
    Posts
    87
    What i think this is aiming at is that you can't use cin to get a string. i think you need a getline. Something like

    getline(cin, Species[s])

    not sure if you need any other parameters...

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    208
    and u don't need to loop it b/c it looks like u are trying to use the loop for each letter if u use getline( ) then u don't need the for loop unless u want is to ask the name of the specis over and over
    which may be the case I dunno
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    he actually has an array of strings, so he is entering separate species.

    as previously said, try using getline for names including whitespace, because once whitespace is hit, cin stops.

    you can disregard my last post, i meant to say if the for loop is ended with a }, which it probably is and just isn't posted, especially if the code compiles.
    otherwise, i don't see anything wrong with it, and you shouldn't be getting the >> error.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21