Posted By

somada141 on 03/12/10


data file String function read binary stream

Versions (?)

Read alpharithmetic binary data using fstreams

 / Published in: C++

  1. //this function takes a reference to the file input stream and the number of characters to read from the file
  2. string fread_char(ifstream &input_file,int no_characters) {
  4. char temp[no_characters]; //initially we create an appropriately sized 'char' array
  5.,(no_characters)*sizeof(char));//we read the characters. note how we specify the number of bytes
  6. string str(temp); //we convert the 'char' array to a string and return it
  7. return str;
  8. }
  10. ifstream input_data;
  11."input.dat",ios::in | ios::binary); //note the modifiers that denote both input file and binary mode
  12. reg_name=fread_char(input_data,name_length);

Report this snippet  

You need to login to post a comment.