2011-09-01 12 views

risposta

6

readline e leggere funzioni dovrebbe ottenere quello che stai cercando.

In sostanza:

  1. Aprire il file
  2. Usa readline per ottenere la riga successiva da file in un buffer di linea
  3. Usa lettura per analizzare il buffer di linea per dati utili
  4. (opzionale) convertire il valore analizzato se necessario

Snippet di codice:

library STD; 
use std.textio.all; 
... 
variable File_Name   : string; 
file my_file    : text; 
variable lineptr   : line; 
variable temp    : integer; 
... 
file_open(my_file, File_Name, read_mode); -- open the file 
readline(my_file, lineptr); -- put the next line of the file into a buffer 
read(lineptr, temp); -- "parse" the line buffer to an integer 
-- temp now contains the integer from the line in the file 
... 
+0

Quel signore è una gustosa risposta. Grazie! –

4

Per riferimento. E 'anche possibile convertire una stringa a intero utilizzando l'attributo 'value:

variable str : string := "1234"; 
variable int : integer; 
... 

int := integer'value(str); 

seconda di una necessità puo essere più desiderabile rispetto alla procedura read() perché non distruttivo altera la stringa di origine. Tuttavia, funziona solo se la stringa è un valore letterale intero valido senza caratteri circostanti diversi da spazi vuoti.

variable ln : line; 
variable int : integer; 
... 

ln := new string'(" 456 "); -- Whitespace will be ignored 
int := integer'value(ln.all); -- Doesn't consume contents of ln 

ln := new string'("789_000 more text"); 
int := integer'value(ln.all); -- This will fail unlike read() 
Problemi correlati