#what the heck does this error mean? and how can i fix it?

15 messages · Page 1 of 1 (latest)

raven comet
#

Hi, I am working on a program right now that will take in a .pgm file, and output "test" if it successfully does it. I have an image.h file that creates a class, an image.cpp file that holds the code to output "test", and the main.cpp which takes in the file itself and outputs test.

the image.h code looks like this:

class PGM {
    public:
    string title;        //the title. P2, P3, P4, etc
    string comment;        //the comment inside the PGM file
    int x_val;            //used for the x-axis
    int y_val;            //will be used for the y-axis
    int tolerance;        //how many numbers will be used
    
    PGM(stringstream v);
};```

the image.cpp file has this in it:

```c++
//constructor for reading PGM image
PGM::PGM(stringstream v) {

        if (title.compare("P2") != 1) {    //if it doesn't equal x..
            cout << "You have entered the wrong file!\n";
        }
        else {
            cout << "test\n";
        }

}```

the main file is simple, and looks like this:

```c++
int main() {
    int val;

    ifstream infile("pgm.pgm");
    stringstream sstream;

    PGM m(sstream);
}```

my issue arises on the PGM m(sstream) chunk in main.cpp. It displays the code that you see in the provided screenshot, and I have no idea what this means. I am new to c++ so this is a completely new wacky issue for me. I know the code has some errors in it too at the moment but my main issue is why the error in the picture is showing up. any help would be appreciated.
storm agateBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

blissful coyote
#

streams cannot be copied

#

You have to pass to either pass them by reference, or move them into the function

raven comet
#

i guess i am not entirely sure how i would go about that, do you have any recommendations or suggestions for how to pass them by reference?

blissful coyote
#

Most important question, is the constructor just gonna use the stream only at construction, or is it going to keep the stream

#

The answer is slightly different between the two

raven comet
#

my idea was for the constructor to use the stream and keep it until i use a destructor afterwards

blissful coyote
#

then in that case what you can do is

int main() {
    int val;

    ifstream infile("pgm.pgm");
    stringstream sstream;

    PGM m(std::move(sstream));
}
#

so now instead of copying the stream, it will move the stream

#

Basically m sucks the essence of sstream for itself, leaving sstream empty, but having its own version that is identical to how it was

storm agateBOT
#

@raven comet Has your question been resolved? If so, run !solved :)

raven comet
#

!solved