How to initialize declared istringstream with string?

1873 views c++
7

In C++, how do you initialize a declared istringstream with a string?

example.hpp

#include <sstream>
class example{
    private:
        istringstream _workingStream;
    public:
        example();
}

example.cpp

example::example(){
    this->_workingStream("exampletext");
}

Error

error: no match for call to ‘(std::istringstream {aka std::basic_istringstream}) (const char [8])’

answered question

1 Answer

12

To construct a class member you need to use the class member initialization list. Once you are inside the body of the constructor all class members have all be constructed and all you can do is assign to them. To use the member initialization list you need to change the constructor to

example::example() : _workingStream("exampletext") {}

posted this

Have an answer?

JD

Please login first before posting an answer.