从c++到Delphi的转换(简单)
Conversion from C++ to Delphi (simple)
我在c++中有一个函数,我试图在delphi中复制:
typedef double ANNcoord; // coordinate data type
typedef ANNcoord* ANNpoint; // a point
typedef ANNpoint* ANNpointArray; // an array of points
bool readPt(istream &in, ANNpoint p) // read point (false on EOF)
{
for (int i = 0; i < dim; i++) {
if(!(in >> p[i])) return false;
}
return true;
}
在Delphi中,我相信我已经正确地声明了数据类型。(我可能错了):
type
IPtr = ^IStream; // pointer to Istream
ANNcoord = Double;
ANNpoint = ^ANNcoord;
function readPt(inpt: IPtr; p: ANNpoint): boolean;
var
i: integer;
begin
for i := 0 to dim do
begin
end;
end;
但是我不知道如何模仿c++函数中的行为(可能是因为我不理解位移操作符)。
此外,我需要最终弄清楚如何将点集从Zeos TZQuery
对象转移到相同的数据类型-所以如果有人对此有一些任何输入,我将非常感激。
尝试:
type
ANNcoord = Double;
ANNpoint = ^ANNcoord;
function readPt(inStr: TStream; p: ANNpoint): boolean;
var
Size: Integer; // number of bytes to read
begin
Size := SizeOf(ANNcoord) * dim;
Result := inStr.Read(p^, Size) = Size;
end;
不需要分别读取每个ANNcoord。注意,istream在c++中是一个流类,而不是istream接口。Delphi的等效物是TStream。代码假设流已打开以供读取(使用适当的参数创建-d),并且当前流指针指向anncord的一个数字(dim),就像c++代码一样。
fww in >> p[i]
从输入流in
读取ANNcoord
到p[i]
,将p
解释为指向ANNcoords
数组的指针。
正如Rob Kennedy指出的那样,in >> myDouble
从输入流中读取双精度,但该流被解释为文本流,而不是二进制,即:
1.345 3.56845 2.452345
3.234 5.141 3.512
7.81234 2.4123 514.1234
etc...
在Delphi中没有等价的流方法或操作。只有System.Read
和System.Readln
用于此目的。显然,Peter Below曾经写过一个unit StreamIO
,使得System.Read
和System.Readln
可以用于流。我只能在一个新闻组帖子里找到一个版本。
为可以从文本表示中读取双精度、整数、单精度等的流编写一个包装器可能是有意义的。我还没看过
相关文章:
- C++ 将静态方法转换为简单方法
- 有没有简单的方法可以将"02:00"转换为分钟,比如 120?
- 在C++中将算术类型转换为 std::array 的最简单方法<uint8_t>
- C++-将ASCII字符数组中可能的数值转换为字符的最简单方法
- 有没有一种简单的方法可以将矢量 int 集转换为字符串输出?
- 在这个简单函数中从'char'到'const char*'的无效转换
- FFMpeg与OpenCV的格式转换/简单转换
- 有没有一种简单的方法可以将系统命令的输出转换为字符串
- 运算符重载:简单添加...错误 C2677:二进制"+":未找到采用类型 ___ 的全局运算符(或者不存在可接受的转换)
- 将整数字符串转换为整数的最简单方法
- 简单的 int 到字符串转换..int to const char* 无效
- 简单的递归转换
- 错误:在非常简单的示例中,预期的构造函数、析构函数或类型转换
- 将简单的 C 加密转换为C++
- 为什么模板重载比简单的转换更匹配
- C++简单的矢量程序中从 int 类型转换为非标量类型
- 是否有Visual c++编译器在线,以及如何在c++和vs简单代码之间转换
- 如何将简单指针转换为固定大小的多维数组
- java到C++的简单转换1行
- C++从二进制到十进制的简单转换