写整数到文件vhdl[英] write integer to file vhdl

本文是小编为大家收集整理的关于写整数到文件vhdl的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我想在文件(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文件,我会阅读 b0000000000000000000000000000000000101000 .这似乎是一个地址或其他东西.我希望阅读 40 .

推荐答案

而不是尝试write(line_var, integer'image(num));.它会将变量num转换为小数字符串.

本文地址:https://www.itbaoku.cn/post/2091005.html

问题描述

I would like to write an integer (variable num) on a file (write.txt). Here my code but obviously it does not work. Any suggestion?

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;

After running the synthesis, If I open write.txt file, I read b00000000000000000000000000101000. It seems an address or something else. I expected to read 40.

推荐答案

Try write(line_var, integer'image(num)); instead. It will convert the variable num to a decimal string.