将整数写入文件vhdl

write integer to file vhdl

我想在文件 (write.txt) 上写入一个整数(变量 num)。这是我的代码,但显然它不起作用。有什么建议吗?

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.MATH_REAL.ALL;
library std;
use std.textio.all;

entity file_handle is
end file_handle;

architecture Behavioral of file_handle is

begin

process

variable line_var : line;
file text_var : text;
variable num : integer := 40;

begin        
    file_open(text_var,"C:\Users\Tommy\Desktop\write.txt", write_mode);
    write(line_var, num);         -- write num into line_var
    writeline(text_var, line_var);   -- write line_var into the file
    file_close(text_var);
end process;

end Behavioral;

在 运行 合成后,如果我打开 write.txt 文件,我会读取 b000000000000000000000000000101000。好像是地址什么的。我希望阅读 40.

试试 write(line_var, integer'image(num));。它将变量 num 转换为十进制字符串。