write integer to file vhdl

梦想的初衷 提交于 2019-12-11 13:48:47

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/32681055/write-integer-to-file-vhdl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!