-2
    int main()
    {
        char buffer[1024];
        ifstream dataFile ("./data.dat");
        while(buffer)
        {
            localHouse->location = dataFile.getline(buffer, 1024);
        }
}

This throws the error: No suitable converion function from "std::basic_istream<char, std::char_traits<char>>" to "char" exists.

It continues to throw this error if I use a pointer to buffer instead. as far as I can tell I'm using it exactly as seen in the example here.

There's another example on stackoverflow here

That shows similar usage but I can't get it to work, and it's really causing me to tear my hair out over an error that seems to say it can't convert from the char to char. >.<

Community
  • 1
  • 1
Yakri
  • 97
  • 1
  • 1
  • 9
  • 1
    Well, what does `getline()` return? That said, use the free (unbound, non-member) `getline()` function instead and use a `std::string` instead of the fixed-size buffer. Then, please reduce your code next time, the definition of `House` is missing, but probably irrelevant. Also, don't use `new` unless you have to. Don't try to use it as in Java or C#! – Ulrich Eckhardt May 12 '15 at 05:38
  • It returns a c-string, like char x[10]. I'm working on this as a minor part of a larger program for a datastructures class in which we are not allowed to use string for because of reasons. Also this is c++ not Java or C#, I had a reason to use new. – Yakri May 12 '15 at 05:48
  • No it [`getline()`] doesn't return "a c-string, like char x[10]". Also, there is no appearent reson in the code you have shown to use `new`. Other code outside of what you have shown here is irrelevant, as the code you post here is supposed to be a minimal example. Even instantiating `House` at all is unnecessary, just creating an instance of whatever `location` inside `House` is should be enough. – Ulrich Eckhardt May 12 '15 at 17:46
  • Yes it does. http://www.cplusplus.com/reference/istream/istream/getline/ – Yakri Oct 04 '17 at 23:52
  • Or rather, it returns into a c-string, which is functionally identical here. – Yakri Oct 05 '17 at 16:38
  • I think you misunderstand the documentation at the link you gave. It doesn't return anything string-like but an `istream&`, which is a typedef for a `basic_istream>&` (omitting the `std` namespace). Writing into a buffer is similar, but that is not what the error message is about. That's why you should have provided a minimal example. You would have found that the call to `getline()` is not the problem but that the assignment of what it returns is. – Ulrich Eckhardt Nov 04 '17 at 14:13

1 Answers1

2

getline's return value is the istream object which I guess it's not something that you want to assign to localHouse->location. getline reads a line of your file into buffer variable that you have provided as the first parameter.

MSH
  • 417
  • 5
  • 11