I've a file named "assad.txt" on my desktop. I want to read it through C++ files. Can anybody tell me the syntax how can i open this file in Visual C++ 6.0??
what i am doing is...
fstream file; // object i made
file.open("assad.txt", ios::in); // Open in read mode
Perhaps you can start by reading this site's tutorial on files: http://cplusplus.com/doc/tutorial/files/
It will show you the easiest way to read lines of text from a simple text file.
In your code above, the line you ask about reads sizeof(rec) characters into the buffer rec. It's a bit difficult to give details without seeing the definition of rec, though.
Firstly, you should check if the file was opened successfully, using file.is_open(), which returns true if it is opened and false if not (e.g. if the file wasn't found).
Anyway, to the point. From this site's documentation:
[quote=cplusplus.com]
istream& read ( char* s, streamsize n );
s
Pointer to an allocated block of memory where the content read will be stored.
n
Integer value of type streamsize representing the size in characters of the block of data to be read.
[/quote]
So it reads n characters from the file into the buffer s. You must therefore create a buffer to read into, for example a character array.
What are you trying to read from the file, and how is it arranged? There might be easier ways than using fstream::read.