[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Error C2678: binary '!=': no operator found...

Posted on 2016-11-11
4
Medium Priority
?
102 Views
Last Modified: 2016-11-12
Hello all.

I'm doing some basic work with C++ streams on MS Visual Studio 2015, and I am encountering error C2678 when I attempt to compile this code:

#include <iostream>

using namespace std;

int main()
{
	char ch;
	cout << "enter a phrase: ";
	while ( cin.get(ch) != 0 )
	{
		if (ch == '!')
			cin.putback('$');
		else
			cout << ch;
		while (cin.peek() == '#')
			cin.ignore(1, '#');
	}
	return 0;
}

Open in new window


For line 9, I receive this error output:
C2678      binary '!=': no operator found which takes a left-hand operand of type 'std::basic_istream<char,std::char_traits<char>>' (or there is no acceptable conversion)

Many thanks in advance!
0
Comment
Question by:blossompark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 32

Accepted Solution

by:
phoffric earned 2000 total points
ID: 41884329
According to this link, you are using a form of get that returns basic_istream& and I did not find a != operator that addresses a LHS of basic_istream& and a RHS of int.
http://www.cplusplus.com/reference/istream/basic_istream/get/

The revised while test condition should get your program to build.
But you still have a peek to deal with when you reach the EOF. Here is one approach. Adding in a test for EOF in a peek() allows your program to run smoothly in VS until you hit the eof state. At that point, to emulate an eof in the Visual Studio console, you type in the single char, ctrl/Z, followed by the <ENTER>, at which point you hit the break and your program ends.
	while (cin.get(ch) )
	{
		if (cin.peek() == std::char_traits<char>::eof())
			break;

Open in new window

or you can combine these three lines as follows:
	while( ( ch = cin.get() ) != std::char_traits<char>::eof() )

Open in new window

0
 
LVL 32

Assisted Solution

by:phoffric
phoffric earned 2000 total points
ID: 41884333
Just curious - I see that you just started C++ questions after a good deal of DB questions. Did you volunteer to take on new projects where you have to figure this stuff out?
0
 

Author Comment

by:blossompark
ID: 41884618
Thank you, it worked like a charm.

And, I'm actually borrowing this account at the moment. The DB questions aren't mine (though I hope to work my way through that subject as well!)

Many thanks.
0
 
LVL 32

Expert Comment

by:phoffric
ID: 41884808
I think that you can create your own account for free and ask your own questions for free. There is also a premium membership that gives you extra privileges.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question