Hey, I'm new to programming in C++

So I just got done writing this and everything seems fine to me, but I got an errors. I've had many problems with compilers in the past, but I'm not sure if this is from the code or the compiler.

If it helps I'm running Windows7 64bit and using DevC++ (mingw)

#include <iostream>
using namespace std;

int main ()
{

int a;
int b;

cout << "lets add numers, enter you first number";
cin >> a;
cout << "enter your second number";
cin >> b;
cout >> (a + b);

return 0;
}

This is the problem

\test.cpp In function `int main()':
\test.cpp no match for 'operator>>' in 'std::cout >> (a + b)'
\Makefile.win [Build Error] [test.o] Error 1

I've scanned through it many times, but I still cant figure out whats wrong. Did I do anything wrong?

I found out what I did wrong, you can go ahead and delete this ^_^

Dani AI

Generated

A simple typo was the root cause here, as and pointed out: the program used the input/extraction operator on the output stream by mistake. That produces the compiler message about "no match for operator" because std::cout is an ostream and the extraction operator isn't overloaded for it. The iostream operators are separate: one set (insertion) sends data to output streams, the other set (extraction) reads data from input streams. A short reference on how those stream operators are defined is here: operator<< (basic_ostream).

Practical debugging tips for similar mistakes:

  • Read the compiler error and check the exact line number; it usually points straight to the operator you mistyped.
  • Build with warnings enabled (for g++ use -Wall -Wextra -std=c++11) so you catch other issues early.
  • If prompts sometimes fail to appear before input, remember stream buffering and flushing: tie/flush behavior can affect whether a prompt is visible before a cin call. Explicitly add a newline or flush when needed.

A few small best practices to avoid future traps: initialize variables before use, validate input after extraction, and consider using a modern toolchain (MinGW-w64, Visual Studio, or an up-to-date IDE) instead of very old Dev-C++ releases. The original error was trivial to fix, but the workflow above makes catching and preventing similar slips faster and less frustrating.

Recommended Answers

All 4 Replies

Look closer at line #14:

cout >> (a + b);

you're using the wrong operator. Use cout << instead of cout >>

you're using the wrong operator. Use cout << instead of cout >>

Yeah, already seen and fixed this.

Not in the code you posted. I'm not clairvoyant you know :icon_wink:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.