fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. cout <<"enter array" ;
  6. map <int , int> arr ;
  7. cout<<"enter size of array" ;
  8. int n ;
  9. cin >> n ;
  10. int m = n ;
  11. while(m--)
  12. {
  13. int x ;
  14. cin >> x ;
  15. arr[x]++ ;
  16. }
  17. for(int i = 0 ; i < arr.size() ; i++)
  18. {
  19. cout << arr->first <<" has frequency : " << arr->second <<endl;
  20. }
  21. return 0;
  22. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
5
1 2 3 1 2
compilation info
prog.cpp: In function 'int main()':
prog.cpp:19:14: error: base operand of '->' has non-pointer type 'std::map<int, int>'
   cout << arr->first <<" has frequency : " << arr->second <<endl;
              ^
prog.cpp:19:50: error: base operand of '->' has non-pointer type 'std::map<int, int>'
   cout << arr->first <<" has frequency : " << arr->second <<endl;
                                                  ^
stdout
Standard output is empty