注册 登录
编程论坛 C++教室

这个错误是为啥?怎样改正?

冷月·葬花魂 发布于 2018-06-26 15:11, 1598 次点击
d:\专业\vc6\myprojects\行文本编辑器\行文本编辑器3\linklist.h(66) : error C2664: '__thiscall fstream::fstream(int)' : cannot convert parameter 1 from 'char [12]' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
        d:\专业\vc6\myprojects\行文本编辑器\行文本编辑器3\linklist.h(63) : while compiling class-template member function 'void __thiscall LinkList<char>::Showwenben(void)'
Error executing cl.exe.
代码如下
void Showwenben()//显示当前文本
    {
        cout<<"当前文本是:"<<endl;
        int i,j;
        fstream examplefile("example.txt");//错误行
        for(i=0;i<hang;i++)
        {
            
            for(j=0;j<lie;j++)
            {
                cout<<wenben[i][j];
                if (examplefile.is_open())
                {
                    examplefile<<"wenben[i][j]";
                    
                }
               
            }
            examplefile.close();
            cout<<endl;
        }
    }
};
3 回复
#2
Myloop2018-06-26 23:15
你这个函数是想先在控制台输出wenben数组的某个元素然后将该元素写入到文件中,是吗
#3
Jonny02012018-06-27 10:27
我这里运行没错
fstream::fstream(int)
你编译器上的 fstream 是这样的
根据你编译器的具体实现对症下药
#4
rjsp2018-06-27 11:00
回复 3楼 Jonny0201
题主用的 VC6,fstream.h中的标准头
fstream examplefile("example.txt"); 改为 fstream examplefile("example.txt",ios::out); 或许可以
1