c++ error C2676
hi!!
i just started programming some stuff in c++.
i made a simple program that compares a number given by the user to 0 n say if its cero, positive or negative.
// num_positivo_negativo.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <math.h>
#include <windows.h>
#include <stdio.h>
#include <iostream> //para las versiones nuevas de C++
#include <iostream.h> //para las versiones más viejas, como Borland C++
int main(int argc,char* argv[])
{
int num;
cout << " Ingrese un número: ";
cin << num;
if (num = 0)
{
cout << "El número es igual a cero"; // says that is 0
}
else
if (num < 0)
{
cout <<"Numero negativo"; // says that is negative
}
else
{
cout <<"Numero positivo"; // says that is positive
}
return 0;
}
but, then it gave me this error:
num_positivo_negativo.cpp(17) :error C2676: binary '<<' : 'class istream_withassign' does not define this operator or a conversion to a type acceptable to the predefined operator
hope some1 can help me
thanks!!
cyaa!!
gispe!! :)
gispe
Junior Poster in Training
74 posts since Jul 2008
Reputation Points: 6
Solved Threads: 0
You don't want this:
cin << num;
you want this:
cin >> num;
Also, be careful here not to confuse the = (assignment) operator and the == (comparison) operator.
if (num = 0)
= should == in the line above.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
thanks
didnt realized the last thing!!
thanks a lot
gispe
Junior Poster in Training
74 posts since Jul 2008
Reputation Points: 6
Solved Threads: 0
Don't include . It's so called old stream header. Say him Nevermore. Use only.
You wrote #include <stdafx.h> - Visual C++ precompiled header. Place all subsequent includes in stdafx.h wizard-generated file. No need in math.h, windows.h and stdio.h headers in your program now. You may add them (in stdafx.h) later.
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348