读取用C++;python中的生成器 在C++ Builder中有数据创建功能文件: int HandleFile; if (!FileExists(fnm)) {HandleFile = FileCreate(fnm);FileClose(HandleFile);} HandleFile = FileOpen(fnm,fmOpenWrite); if(! HandleFile) {return 0;} AnsiString str = IntToStr(num)+"#" +IntToStr( GetLastError() )+": "+ AnsiLastError(); FileSeek(HandleFile,0,2); FileWrite(HandleFile, &str, sizeof(str)); FileClose(HandleFile); return 1;
有没有办法用python阅读它? 当我用记事本打开文件时,我只看到无法识别的符号读取用C++;python中的生成器 在C++ Builder中有数据创建功能文件: int HandleFile; if (!FileExists(fnm)) {HandleFile = FileCreate(fnm);FileClose(HandleFile);} HandleFile = FileOpen(fnm,fmOpenWrite); if(! HandleFile) {return 0;} AnsiString str = IntToStr(num)+"#" +IntToStr( GetLastError() )+": "+ AnsiLastError(); FileSeek(HandleFile,0,2); FileWrite(HandleFile, &str, sizeof(str)); FileClose(HandleFile); return 1;,python,c++,file-io,c++builder,readfile,Python,C++,File Io,C++builder,Readfile,有没有办法用python阅读它? 当我用记事本打开文件时,我只看到无法识别的符号 FileWrite(HandleFile, &str, sizeof(str)); 这是不对的 需要指向原始缓冲区的指针,并将缓冲区的x字节写入HandleFile给定的文件 AnsiString对象包含一个指向存储所有数据的堆(以及一些其他变量)的指针。所以sizeof(str)!=str.Length()和&str!=str.c_str() 你应该这样写: FileWrite(HandleFile,
FileWrite(HandleFile, &str, sizeof(str));
这是不对的
需要指向原始缓冲区的指针,并将缓冲区的x
字节写入HandleFile
给定的文件
AnsiString
对象包含一个指向存储所有数据的堆(以及一些其他变量)的指针。所以sizeof(str)!=str.Length()
和&str!=str.c_str()
你应该这样写:
FileWrite(HandleFile, str.c_str(), str.Length());
不管怎样,看看,这可能是你需要的
这是不对的
需要指向原始缓冲区的指针,并将缓冲区的x
字节写入HandleFile
给定的文件
AnsiString
对象包含一个指向存储所有数据的堆(以及一些其他变量)的指针。所以sizeof(str)!=str.Length()
和&str!=str.c_str()
你应该这样写:
FileWrite(HandleFile, str.c_str(), str.Length());
无论如何,请看一看,它可能是您所需要的。此代码无法重写,并且不是由我编写的。其中的数据是二进制格式的!我试着用numpy阅读它,比如:import numpy作为np f=open(“1.dbo”,“r”)a=np.fromfile(f,dtype=np.uint32),列表中只有整数。是获取字符串where Is string和int where int的一种方法吗?@user3216321文件中没有
string
/int
,只有一系列字节编码AnsiString
的私有数据成员。文件应该包含什么?日期和值(int,float),simbols'#',可能是'()'。不知道excactly@user3216321如所解释的,你所发布的C++代码有一个严重的问题,它不写代码< STR 字符串的内容,而是别的东西。如果代码不能重写(为什么不),那么你就不走运了。当前代码正在生成一个已损坏的文件!没有任何东西能够理解该文件,因为首先没有任何有意义的东西被写入该文件。基本上,文件内容是ansisting
中char*
指针的二进制数值。文件内容不是ansisting
指向的字符串。该指针值在分配所指向内存的进程之外是无用的。此代码无法重写,并且不是由我编写的。其中的数据是二进制格式的!我试着用numpy阅读它,比如:import numpy作为np f=open(“1.dbo”,“r”)a=np.fromfile(f,dtype=np.uint32),列表中只有整数。是获取字符串where Is string和int where int的一种方法吗?@user3216321文件中没有string
/int
,只有一系列字节编码AnsiString
的私有数据成员。文件应该包含什么?日期和值(int,float),simbols'#',可能是'()'。不知道excactly@user3216321如所解释的,你所发布的C++代码有一个严重的问题,它不写代码< STR 字符串的内容,而是别的东西。如果代码不能重写(为什么不),那么你就不走运了。当前代码正在生成一个已损坏的文件!没有任何东西能够理解该文件,因为首先没有任何有意义的东西被写入该文件。基本上,文件内容是ansisting
中char*
指针的二进制数值。文件内容不是ansisting
指向的字符串。该指针值在分配指向的内存的进程之外是无用的。