将整数写入文件vhdl [英] write integer to file vhdl
本文介绍了将整数写入文件vhdl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在文件(write.txt)上写一个整数(变量num).这是我的代码,但显然不起作用.有什么建议吗?
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;
运行综合后,如果打开write.txt文件,则会读取 b0000000000000000000000000000101000 .似乎是地址或其他内容.我希望读 40 .
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.
推荐答案
请尝试使用write(line_var, integer'image(num));
.它将把变量num
转换为十进制字符串.
Try write(line_var, integer'image(num));
instead. It will convert the variable num
to a decimal string.
这篇关于将整数写入文件vhdl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文