whats wrong with my code?

This is a discussion on whats wrong with my code? within the C++ Programming forums, part of the General Programming Boards category; Its keeps on saying this. (41) : error C2679: binary '>>' : no operator defined which takes a right-hand operand ...

  1. #1
    Unregistered
    Guest

    whats wrong with my code?

    Its keeps on saying this.

    (41) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > [10]
    ' (or there is no acceptable conversion)
    Error executing cl.exe.

    PRO3LECT5.exe - 1 error(s), 0 warning(s)

    -----------------------------------------------------------------------------------

    #include <iostream>
    #include <fstream>
    #include <string>
    #include <cstdlib>
    using namespace std;

    void main()
    {

    ifstream in_stream;
    ofstream out_stream;


    in_stream.open("input.dat");
    if(in_stream.fail())
    {
    cout << "ERROR IN INDATA.DAT" <<endl;
    exit(1);
    }

    out_stream.open("output.dat");
    if(out_stream.fail())
    {
    cout << "ERROR IN OUTDATA.DAT" <<endl;
    exit(1);
    }




    string name1[10], name2[10];
    int QZ1, QZ2, QZ3, QZ4, QZ5, QZ6, QZ7, QZ8, QZ9, QZ10;
    double AVG;

    while(!in_stream.eof())
    {




    in_stream >> name1 >> name2 >> QZ1 >> QZ2 >> QZ3 >> QZ4 >> QZ5 >> QZ6 >> QZ7 >> QZ8 >> QZ9 >> QZ10;

    AVG = (QZ1 + QZ2 + QZ3 + QZ4 + QZ5 + QZ6 + QZ7 + QZ8 + QZ9 + QZ10)/10;

    out_stream << name1 << name2 << QZ1 << QZ2 << QZ3 <<QZ4 << QZ5 << QZ6 << QZ7 << QZ8 << QZ9 << QZ10 << AVG << endl;
    }
    in_stream.close();
    out_stream.close();


    }

  2. #2
    Registered User EvenFlow's Avatar
    Join Date
    Oct 2001
    Posts
    422
    perhaps try using .h when you include your header files?

    eg.

    #include<iostream.h>
    Ramble on...

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    8
    You declared your strings incorrectly. Instead of string name1[10],name2[10], use string name1,name2.

    With the string class name[10] refers to the 10th element of the string. It doesn't create a string of 10 elements.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    evenflow

    evenflow, the .h's are the older implementation headers, any new compiler has the .h-less headers (and you'll need to include that "using namespace std line.

    There is a huge difference between <string> and <string.h> also.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    To get an explanation of the error code in msvc, put the cursor on the error number and hit F1. Sometimes it's not very understandable, but sometimes it is. Borland's error messages generally are easier to figure out.

  6. #6
    Registered User EvenFlow's Avatar
    Join Date
    Oct 2001
    Posts
    422
    Really? Didn't know that Cozman. I'm a C programmer by trade, but the way I learnt C++ was to use .h at the end of headers.
    Ramble on...

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    yeah, the STL changed everything around

    STL (Standard Template Library) and the newest C++ standard introduced the common namespace std to deal with function name contradictions in older code. And the old libraries (stdio.h, stdlib.h are now <cstdlib> and <cstdio>)

    Lots of people still use .h's because the only time this causes major problems for you is in the case of <string> and <string.h> as string.h is a set of functions to deal with char*'s and <string> is a header which defines a class to use instead of char*'s (it's very nice, worth learning) and the old <string.h> can be accessed via <cstring>.

  8. #8
    Unregistered
    Guest
    you misplaced ">>" with "<<" or vise versa

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong in this simple code
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 08:10 AM
  2. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 10:11 AM
  3. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 06:32 PM
  4. Anyone see what is wrong with this code?
    By Wise1 in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 02:01 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 01:51 AM

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