how to solve this 2 errors ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chetoos
    New Member
    • Oct 2008
    • 2

    how to solve this 2 errors ?

    #include <iostream.h>
    #include <string>
    using namespace std;
    void output_data(str uct database*data_p tr);
    void input_data(stru ct database*data_p tr);
    struct database {
    int id_number;
    int age;
    float salary;
    string name;
    };
    int main()
    {
    struct database employee;
    struct database* sp;
    sp = &employee;
    input_data(sp);
    output_data(sp) ;
    return 0 ;
    }
    void output_data(str uct database*data_p tr)
    {
    cout << "************** *************** ****\n";
    cout << "name = " << data_ptr->name << "\n";
    cout << "id_num = " << data_ptr->id_number << "\n";
    cout << "age = " << data_ptr->age << "\n";
    cout << "salary = " << data_ptr->salary << "\n";
    cout << "************** *************** ****\n";
    }
    void input_data(stru ct database*data_p tr)
    {
    int i_tmp;
    float f_tmp;
    string s_tmp;
    cout<<"enter name:";
    cin >>s_tmp;data_pt r->name = s_tmp;
    cout << "enter id_number :";
    cin >> i_tmp;data_ptr->id_number = i_tmp;
    cout << "enter age :";
    cin >> i_tmp;data_ptr->age = i_tmp;
    cout << "enter salary:";
    cin >> f_tmp;data_ptr->salary = f_tmp;;
    cout<<endl;
    }






    The 2 errors are :
    C:\Users\Omar\D esktop\Cpp1.cpp (24) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_stri ng<char,struct std::char_trait s<char>,class std::allocator< char> >' (or there is no acceptable convers
    ion)
    C:\Users\Omar\D esktop\Cpp1.cpp (36) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_stri ng<char,struct std::char_trait s<char>,class std::allocator< char> >' (or there is no acceptable convers
  • boxfish
    Recognized Expert Contributor
    • Mar 2008
    • 469

    #2
    You are using the deprecated header iostream.h. Try changing it to
    #include <iostream>
    I think that will make your program work.
    Hope this helps.
    By the way, when you post code, please surround it with code tags. Put [CODE] before it and [/CODE] after it so it shows up in a code box with a monospace font and the indentation isn't wrecked. Thanks.

    Comment

    • chetoos
      New Member
      • Oct 2008
      • 2

      #3
      boxfish thnx alot for ur help and ill take it into consideration next time :)

      Comment

      • AmeL
        New Member
        • Oct 2008
        • 15

        #4
        Please look at this
        Code:
        ...........................................................
        void input_data(struct database*data_ptr)
        {
        int i_tmp;
        float f_tmp;
        string s_tmp;
        cout<<"enter name:";
        cin >>s_tmp;data_ptr->name = s_tmp;
        cout << "enter id_number :";
        cin >> i_tmp;data_ptr->id_number = i_tmp;
        cout << "enter age :";
        cin >> i_tmp;data_ptr->age = i_tmp;
        cout << "enter salary:";
        cin >> f_tmp;data_ptr->salary = f_tmp;;
        cout<<endl;
        }
        Well, the first error as the above forumer stated; change your iostream.h to iostream.
        but the compiler produced two different errors.
        Code:
        //cout<<"enter name:";       <=== this is wrong
        cout << "enter name:";     // <=== this is right
        ...................
        //cout<<endl; <=== this is wrong
        cout << endl;       // this is right
        So the problem is you left no space between cout and <<

        Thanks
        /AmeL

        Comment

        • archonmagnus
          New Member
          • Jun 2007
          • 113

          #5
          Originally posted by AmeL
          ....
          So the problem is you left no space between cout and <<
          ...
          The whitespace in a C++ code is (mostly) irrelevant and (mostly) serves to make the code more readily parsed by humans rather than the compiler. For instance, GCC readily compiles the following (admittedly mangled) code:

          [code=cpp]
          #include <iostream>

          using namespace std;

          int main (int argc, char *argv[])
          {
          unsigned
          short
          xyzzy
          = 0;

          cout
          <<
          "Line 1..."

          <<

          endl<<

          "Line 2..." <<
          endl
          <<"Line 3..."<<endl
          <<"Input Integer value: ";

          cin
          >>
          xyzzy;

          cout<<" Input: " << xyzzy << endl;

          return 0;
          }
          [/code]

          Producing the (rather straightforward ) output:
          [code=text]
          Line 1...
          Line 2...
          Line 3...
          Input Integer value: 4
          Input: 4
          [/code]

          I do believe that the OP's error was simply the inclusion of an outdated library rather than minor spacing issues.

          Comment

          Working...