Hi, I'm doing a very very simple coding, However the compiler apparently does not like my usage of cin and gives me an error: no match for 'operator<<' or 'operator>>' depending on cout or cin.

I've used this many times before but never have encountered this problem trying to use << or >> operators. I suppose I could try to overload it but I shouldn't have to.

#include <stdio.h>
#include <math.h>
#include <iostream.h> 
#include <stdlib.h>

using namespace std;

void calcDCT(int num, float * item)
	float alpha;
	float coS;
	float sum;
	int intensity;
	double PI = 3.14;
	float * dct = new float [num];

	for(int i = 0; i < num ; i++)
		if (i==0)
			alpha = 1/sqrt(2);
			alpha = 1;
		sum = 0;
		for(int j = 0; j < num; j++)
			if (j==0)
				alpha = 1/sqrt(2);
				alpha = 1;
			coS = cos(j*PI*(2*i+1)/(2*num));
			intensity = dct[j];
			sum += sqrt(2/num)*alpha*coS*intensity;
		dct[i] = sum;
	for(int i = 0; i < num; i++)
		cout << dct[i] << endl;

int main() 
	int num;
	float temp;
	cout << "Enter N: ";
	cin >> num >> endl;
	float * item = new float [num];

	for(int i = 0; i < num; i++)
		cout << "Enter intensity value " << i << ": " << endl;
		cin >> temp >> endl;
		item[i] = temp;

	calcDCT(num, item);

	return 0;

cin >> temp >> endl; part gives me a nasty error test.cpp:57: error: no match for ‘operator>>’ in ‘std::cin.std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)(& num))) >> std::endl’ Any input would be deeply appreciated.

8 Years
Discussion Span
Last Post by Prabakar

Thanks, Prabakar.

On a somewhat related note, I also have linking problems. Such as

test.cpp:(.text+0x206): undefined reference to `std::cout'
test.cpp:(.text+0x20b): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
test.cpp:(.text+0x219): undefined reference to `std::cin'
test.cpp:(.text+0x21e): undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'
test.cpp:(.text+0x22c): undefined reference to `operator new[](unsigned int)'

This leads me to believe that there still might be some problems related to operators (or not). I kinda figured out that I need to put -lm at the end to link <cmath> correctly. Is there anything else besides <cmath> and <iostream> that I should include to get rid of such linking problems? Or am I doing something wrong?

Much thanks.


Actually, I answered my own question. Found out that I was using gcc in the makefile rather than g++.g++ includes gcc and more.


You probably should update your usage of the libraries to look like:

#include <cstdio>
#include <cmath>
#include <iostream> 
#include <cstdlib>

using namespace std;
This question has already been answered. Start a new discussion instead.
Be sure to adhere to our posting rules.