/ Published in: C++
Expand |
Embed | Plain Text
//this function takes a reference to the file input stream and the number of characters to read from the file string fread_char(ifstream &input_file,int no_characters) { char temp[no_characters]; //initially we create an appropriately sized 'char' array input_file.read(temp,(no_characters)*sizeof(char));//we read the characters. note how we specify the number of bytes string str(temp); //we convert the 'char' array to a string and return it return str; } ifstream input_data; input_data.open("input.dat",ios::in | ios::binary); //note the modifiers that denote both input file and binary mode reg_name=fread_char(input_data,name_length);
You need to login to post a comment.
