繁体   English   中英

如何使用字符串初始化声明的istringstream?

[英]How to initialize declared istringstream with string?

在C ++中,如何使用字符串初始化声明的istringstream?

example.hpp

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

example.cpp

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

错误

错误:对“(std :: istringstream {aka std :: basic_istringstream})(const char [8])”的调用不匹配

要构建类成员,您需要使用类成员初始化列表 一旦进入构造函数的主体,所有的类成员都将被构造,您所能做的就是分配给他们。 要使用成员初始化列表,您需要将构造函数更改为

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM