c++中fstream指针的映射
map of fstream pointers in c++
我想有一个(int, fstream*)的映射,并使用一些函数修改它。我可以很容易地在main中修改它,但如果我想通过发送指针到fstream来使用它,我得到了这个编译器错误:错误C2440: '=':不能从'std::fstream'转换为'std::basic_fstream<_Elem,_Traits> *'
map<int, fstream*> m;
void func(fstream* f){
m[0] = *f; //compile error
}
int main( int argc, const char* argv[] )
{
fstream f("hi.txt");
func(&f); //error
m[0] = &f; //work fine
f.close();
system("pause");
}
我怎样才能改变它?
不要在函数内部取消对指针的引用。
使用void func(fstream* f){
m[0] = f; //no more compile errors
}
相关文章:
- 如何在 C# 中映射双 C 结构指针?
- 智能指针作为无序映射键,并通过引用进行比较
- C++:映射结构中的结构指针
- 如何创建对象函数指针C++映射?
- 整数键映射到头文件中的成员函数指针
- C++在一个映射中存储不同的指针类型(并处理销毁)
- 添加要映射的对象的唯一指针
- 通过指针或引用将映射传递给函数?
- 在映射中存储模板类函数指针
- c++:复制、删除和运算符=在原始指针映射中
- 将唯一指针插入std::映射
- 在循环(C++)中用新指针填充映射
- C++:如何初始化包含具有给定键的指针列表的映射
- 如何将带指针的结构插入到映射中
- 重构MFC消息映射以包括完全限定的成员函数指针
- C 正确的方法来初始化和处理映射指针
- 定义基于模板的映射指针,以便在验证范围时将 int 解析为枚举
- C++中的静态无序映射指针初始化
- 动态分配映射指针值
- 如何在c++中维护映射指针的向量