Alin Catalin Preda
Alin Catalin Preda

Reputation: 141

I'm getting the error: no suitable conversion function from std::basic_istream<char, std::char_traits<char>> to char exists

I'm trying to overload the operator >> and I want to read each character from an input but i get that error. Here is the code:

istream& operator>>(istream& input, Natural_Big_Number number)
{
    int x;
    input >> x;
    number.set_nr_digits(x);
    char c;
    while ((c = input.get(c)))
    {

    }
}

Upvotes: 0

Views: 584

Answers (1)

xaxxon
xaxxon

Reputation: 19751

You need to not specify a parameter to .get() if you want it to return the character. https://en.cppreference.com/w/cpp/io/basic_istream/get

#include <iostream>
using namespace std;

istream& operator>>(istream& input, int number)
{
    char c;
    while ((c = input.get()))
    {

    }
}

https://godbolt.org/z/XSKvv4

If what you want is to check the boolean value of the stream for falseness, then you would do what was mentioned in the comments, instead:

while (input.get(c))  

which stores the character in c then checks the bool value of the returned input stream.

Upvotes: 1

Related Questions