By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,275 Members | 1,937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,275 IT Pros & Developers. It's quick & easy.

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

P: 1
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<iomanip.h>
  4. class sorting
  5. {
  6. private:int n,m[100];
  7. public:  void getdata();
  8.          void sort();
  9.          void display();
  10. };
  11. void sorting::getdata()
  12. {
  13.  cout<<"how many elements?";
  14.  cin>>n;
  15.  cout<<"enter the elements";
  16.        for(int i=0;i<n;i++)
  17.            cin<<m[i];
  18. }
  19. void sorting::sort()
  20. {
  21.  int temp,j;
  22.  for(int i=0;i<n;i++)
  23.     {
  24.         j=i;
  25.            while(j>=i)
  26.         {
.
.
.
.the error is in line 18
Jan 18 '20 #1
Share this Question
Share on Google+
7 Replies


dev7060
Expert 100+
P: 183
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:

Expand|Select|Wrap|Line Numbers
  1. ...
  2. for(int i=0;i<n;i++)
  3. cin>>m[i];
  4. }
  5. ...
  6.  
Jan 18 '20 #2

P: 94
Differences between standard (ansi) C++ and C (ansi) code.

1.include
<C>
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<iomanip.h>
  4.  
<c++>
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<conio>
  3. #include<iomanip>
  4.  
2.standard I/O
<c>
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int n;
  5.     printf("how many elements?\n");
  6.     scanf( "%d", &n );
  7.     printf("enter the elements?\n");
  8.     :
  9.     :
  10. }
  11.  
<c++>
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n;
  6.     cout << how many elements?";
  7.     cin >> n;
  8.     cout << "enter the elements";
  9.     :
  10.     :
  11. }
  12.  
Jan 20 '20 #3

dev7060
Expert 100+
P: 183
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++.
Jan 20 '20 #4

P: 94
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.

Expand|Select|Wrap|Line Numbers
  1. #include "pch.h"
  2. #include <iostream>
  3. #include<conio.h>
  4. #include<iomanip>
  5.  
  6. using namespace std;
  7. class sorting
  8. {
  9. private:int n, m[100];
  10. public: void getdata();
  11.         void sort();
  12.         void display();
  13. };
  14. void sorting::getdata()
  15. {
  16.     cout << "how many elements?";
  17.     cin >> n;
  18.     cout << "enter the elements";
  19.     for (int i = 0;i < n;i++)
  20.     cin >> m[i];
  21. }
  22. void sorting::sort()
  23. {
  24.     int temp, j;
  25.     for (int i = 0;i < n;i++)
  26.     {
  27.         j = i;
  28.         while (j >= i)
  29.         {
  30. :
  31. :
  32.  
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.
Jan 20 '20 #5

dev7060
Expert 100+
P: 183
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.
Jan 20 '20 #6

P: 94
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.


https://bytes.com/topic/c/answers/61...eam-h-iostream

Why doesn’t iostream have a .h extension?
https://www.learncpp.com/cpp-tutoria...omment-page-1/
Jan 20 '20 #7

dev7060
Expert 100+
P: 183
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.
Expand|Select|Wrap|Line Numbers
  1. #include <sysutils.hpp>
  2. #include <iostream.h>
  3. // non-VCL style classes
  4. class MyBase {
  5. public:
  6. MyBase() { what_am_I(); }
  7. virtual void what_am_I() { cout << "I am a base" << endl; }
  8. };
  9. class MyDerived : public MyBase {
  10. public:
  11. virtual void what_am_I() { cout << "I am a derived" << endl; }
  12. };
  13. // VCL style classes
  14. class MyVCLBase : public TObject {
  15. public:
  16. __fastcall MyVCLBase() { what_am_I(); }
  17. virtual void __fastcall what_am_I() { cout << "I am a base" << endl; }
  18. };
  19. class MyVCLDerived : public MyVCLBase {
  20. public:
  21. virtual void __fastcall what_am_I() { cout << "I am a derived" << endl; }
  22. };
  23. int main(void)
  24. {
  25. MyDerived d;// instantiation of the C++ class
  26. MyVCLDerived *pvd = new MyVCLDerived;// instantiation of the VCL style class
  27. return 0;
  28. }
  29.  
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.
Jan 20 '20 #8

Post your reply

Sign in to post your reply or Sign up for a free account.