c++ - 如何用字符串初始化声明的 istringstream?
问题描述
在 C++ 中,如何用字符串初始化已声明的 istringstream?
例子.hpp
#include <sstream>
class example{
private:
istringstream _workingStream;
public:
example();
}
例子.cpp
example::example(){
this->_workingStream("exampletext");
}
错误
错误:不匹配调用 '(std::istringstream {aka std::basic_istringstream}) (const char [8])'</p>
解决方案
要构造一个类成员,您需要使用类成员初始化列表。一旦你进入构造函数的主体,所有的类成员都已经被构造出来,你所能做的就是分配给它们。要使用成员初始化列表,您需要将构造函数更改为
example::example() : _workingStream("exampletext") {}
推荐阅读
- mysql - 随时随地在 RPA 自动化中连接数据库
- python - 使用 matplotlib 轮廓时出现 Pyomo TypeError
- unity3d - 在没有空间映射的情况下在现实世界中定位对象的其他选项;Holo Lens 1 / 混合现实工具包
- django - django-background-tasks 不适用于 django-hosts
- spring-boot - org.springframework.boot 的 PKIX 路径构建失败
- python - 如何在pyqt5中将QAction添加到QLineEdit?
- flutter - Flutter_local_notifications iOS onSelectNotifications 在应用程序关闭时未触发
- python - 有没有办法在滚动窗口中找到倒数第二个有效索引?
- blockchain - 如何在不超时的情况下从 WAX 区块链获取实时交易数据
- linux - QEMU 托管启用 MTE 的内核上的堆栈溢出不会引发错误