Please help me im getting error as, 'illegal structure operation' ,I'm not able to re

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Prathibha v
    New Member
    • Jan 2020
    • 1

    Please help me im getting error as, 'illegal structure operation' ,I'm not able to re

    Code:
    #include<iostream.h>
    #include<conio.h>
    #include<iomanip.h>
    class sorting
    {
    private:int n,m[100];
    public:  void getdata();
             void sort();
             void display();
    };
    void sorting::getdata()
    {
     cout<<"how many elements?";
     cin>>n;
     cout<<"enter the elements";
           for(int i=0;i<n;i++)
               cin<<m[i];
    }
    void sorting::sort()
    {
     int temp,j;
     for(int i=0;i<n;i++)
        {
            j=i;
               while(j>=i)
            {
    .
    .
    .
    .the error is in line 18
    Last edited by gits; Jan 20 '20, 08:35 AM. Reason: added code tags
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    More details from the OP are required on the environment and code for the other party to reproduce the same error. On compiling the code with TDM-GCC 4.9.2, it shows error: no match for ‘operator<<’. It's because the compiler couldn't find a matching overload for operator<<. This can be solved by the following:

    Code:
    ...
    for(int i=0;i<n;i++)
    cin>>m[i];
    }
    ...

    Comment

    • SioSio
      Contributor
      • Dec 2019
      • 272

      #3
      Differences between standard (ansi) C++ and C (ansi) code.

      1.include
      <C>
      Code:
      #include<stdio.h>
      #include<conio.h>
      #include<iomanip.h>
      <c++>
      Code:
      #include<iostream>
      #include<conio>
      #include<iomanip>
      2.standard I/O
      <c>
      Code:
      #include <stdio.h>
      int main()
      {
          int n;
          printf("how many elements?\n");
          scanf( "%d", &n );
          printf("enter the elements?\n");
          :
          :
      }
      <c++>
      Code:
      #include <iostream>
      using namespace std;
      int main()
      {
          int n;
      	cout << how many elements?";
      	cin >> n;
      	cout << "enter the elements";
          :
          :
      }
      Last edited by SioSio; Jan 20 '20, 12:05 PM. Reason: Other users pointed out mistakes.

      Comment

      • dev7060
        Recognized Expert Contributor
        • Mar 2017
        • 656

        #4
        It may have nothing to do with the error,
        This coding looks like a mix of C and C++.
        This code is written purely in C++ and is targeting the pre-standard version of C++. The OP is most probably using an ancient compiler like Turbo C++.

        Comment

        • SioSio
          Contributor
          • Dec 2019
          • 272

          #5
          When I examined about <iostream.h>,
          -<iostream> and <iostream.h> are different headers.
          -It seems that it was abolished in 2006 (or rather, <iostream.h> has never been a part of the standard since the C ++ international standard was enacted in 1998).
          -Only char is supported.

          The code below uses <iostream> instead of <iostream.h> and adds "using namespace std;" after the #include statement.
          And Use Microsoft Visual C ++ 2017, compilation passed.

          Code:
          #include "pch.h"
          #include <iostream>
          #include<conio.h>
          #include<iomanip>
          
          using namespace std;
          class sorting
          {
          private:int n, m[100];
          public: void getdata();
          		void sort();
          		void display();
          };
          void sorting::getdata()
          {
          	cout << "how many elements?";
          	cin >> n;
          	cout << "enter the elements";
          	for (int i = 0;i < n;i++)
          	cin >> m[i];
          }
          void sorting::sort()
          {
          	int temp, j;
          	for (int i = 0;i < n;i++)
          	{
          		j = i;
          		while (j >= i)
          		{
          :
          :
          Line 17 ("cin >> n;" has been modified to "cin << n;") with the following source,
          (Error is "Visual studio: E0349 no operator << matches these operands (but no strings in code)"

          Your compilation environment seems very different from mine, so it is unclear if you can use this modified code.

          Comment

          • dev7060
            Recognized Expert Contributor
            • Mar 2017
            • 656

            #6
            I have pretty much said everything that's required. There is nothing such as a mix of C and C++. A source code file can only be written in one single language with the unique file extension.

            Use Microsoft Visual C ++ 2017, compilation passed.
            You have made changes to the code by making it compatible to the modern compiler (removing .h from iostream.h, adding using namespace std;, etc.) Using Turbo C++, compilation can be done without even making any change to the code.

            Before C++ was standardized, the I/O library was developed as <iostream.h>. Some older compiler continued to distribute the <iostream> header as <iostream.h>. Turbo C++ doesn't support namespaces. Its standard library puts the names in the global namespace. The code by the OP is not a mix of C and C++. The code is purely in C++ targeting the pre-standard version.

            You might need to have a look at official docs that reveal the obsolete C++ programming.

            Comment

            • SioSio
              Contributor
              • Dec 2019
              • 272

              #7
              Hi dev7060.
              Thank you for the information.

              But,
              As mentioned earlier, I have found that <iostream.h> only supports "char".
              This could not be confirmed in my compile environment as <iostream.h> is not supported.




              Why doesn’t iostream have a .h extension?

              Comment

              • dev7060
                Recognized Expert Contributor
                • Mar 2017
                • 656

                #8
                Here's some sample code from the manual of C++ Builder. Differences can be seen like the name of namespace is not mentioned, iostream.h instead of iostream etc.
                Code:
                #include <sysutils.hpp>
                #include <iostream.h>
                // non-VCL style classes
                class MyBase {
                public:
                MyBase() { what_am_I(); }
                virtual void what_am_I() { cout << "I am a base" << endl; }
                };
                class MyDerived : public MyBase {
                public:
                virtual void what_am_I() { cout << "I am a derived" << endl; }
                };
                // VCL style classes
                class MyVCLBase : public TObject {
                public:
                __fastcall MyVCLBase() { what_am_I(); }
                virtual void __fastcall what_am_I() { cout << "I am a base" << endl; }
                };
                class MyVCLDerived : public MyVCLBase {
                public:
                virtual void __fastcall what_am_I() { cout << "I am a derived" << endl; }
                };
                int main(void)
                {
                MyDerived d;// instantiation of the C++ class
                MyVCLDerived *pvd = new MyVCLDerived;// instantiation of the VCL style class
                return 0;
                }
                Source: C++ Builder 6 official manual: http://docs.embarcadero.com/products...rsGuide_EN.pdf

                Why doesn’t iostream have a .h extension?
                Previous replies to this thread and/or own research can answer this question.

                Comment

                Working...