ifstream f ,open的参数只能是常量么?
#include "fstream.h"ifstream data;
extern void __stdcall Get_graphic(char *path,long length)
{
data.open(*path,ios::nocreate);
}
data.open报错
Bin.cpp(28) : error C2664: 'open' : cannot convert parameter 1 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.
是说路径只能是常量么?我想用变量记录路径,然后open这个文件怎么弄啊? path 是char* 类型
*path 是char类型
所以报错了吧。 对了,好奇的问问,你在写什么程序?昨天还在用ruby写打开文件的。 我就是按照文件格式写个提取的玩意。。。RUBY太慢了。。。打开个文件我的本要好几分钟。。。。C++总比ruby快吧
我先试试去。。
家里乱七八糟的书真不少就是没有C++的书。。。
还有,谢谢哈 这是搜索来的哈,别人给的范例
//二进制文件操作示例
#include<fstream.h>
void main()
{
ifstream fin("C:\\\\1.exe",ios::nocreate|ios::binary);
if(!fin){
cout<<"File open error!\\n";
return;
}
ofstream fout("C:\\\\2.exe",ios::binary);
char c;
while(!fin.eof())
{
fin.read(c,1024);
fout.write(c,fin.gcount());
}
fin.close();
fout.close();
cout<<"Copy over!\\n";
}
我写的
#include "fstream.h"
ifstream data;
extern void __stdcall Get_graphic(char *path,long pos)
{
data.open(path,ios::nocreate|ios::binary); //二进制文件格式
if(!data){
return;
}
data.seekg(pos); //绝对移动, //输入流操作
data.close();
}
为什么return这一句会报错呢?
报错内容
C:\\Documents and Settings\\second\\My Documents\\Bin\\Bin.cpp(28) : error C2018: unknown character '0xa1'
C:\\Documents and Settings\\second\\My Documents\\Bin\\Bin.cpp(28) : error C2018: unknown character '0xa1'
C:\\Documents and Settings\\second\\My Documents\\Bin\\Bin.cpp(28) : error C2018: unknown character '0xa1'
C:\\Documents and Settings\\second\\My Documents\\Bin\\Bin.cpp(28) : error C2018: unknown character '0xa1'
执行 cl.exe 时出错.
Bin.dll - 1 error(s), 0 warning(s)
展
这个报错是说Bin.cpp文件的第28行有个未知的字符,和你说的return没有关系吧。奇怪。看这个样子,你是在写dll扩展给RMVX用么? 要看看提取的图形对不对啊。。。 原来是return;前面的空格有问题。。。。。我说怎么return还是黑色的字,而不是蓝色的字的呢,谢谢谢谢啦
页:
[1]