Problem in Reading File.
-
Hi all, i am reading a file with help of CStdioFile using while loop and read the file till file reached end of file,in the file somewhere symbol exist,when reading this line with ReadString ,while loop becomes infinite loop and not return and application goes in notresponding state. please tell me how can i read the full file with this symbol or how can i remove this symbol from file before reading the file. thanks in advance.
-
Hi all, i am reading a file with help of CStdioFile using while loop and read the file till file reached end of file,in the file somewhere symbol exist,when reading this line with ReadString ,while loop becomes infinite loop and not return and application goes in notresponding state. please tell me how can i read the full file with this symbol or how can i remove this symbol from file before reading the file. thanks in advance.
Please post some relevant code.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Please post some relevant code.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
CStdioFile file;
CString str=""; file.Open(file\_name,CFile::modeRead,0); while(file.end) { file.ReadString(str); } file.Close();
Le@rner wrote:
while(file.end)
I don't know where the "end" is coming from (I never used CStdioFile in fact), but if you check the documentation of ReadString[^], you can see that the function returns FALSE when the end of file was reached. You should try to use that.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Le@rner wrote:
while(file.end)
I don't know where the "end" is coming from (I never used CStdioFile in fact), but if you check the documentation of ReadString[^], you can see that the function returns FALSE when the end of file was reached. You should try to use that.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
if i do this ,function not read the full file and return when this symbol occur becoz here ReadFile return 0,but i want to read full file data.
Sorry, your sentence is not clear at all :confused:. There's no ReadFile function, I guess you are talking about ReadString ? Furthermore, the function doesn't read the complete file but only one line, so it is normal that the function return before the end of the file. You have to call it repeatedly until the function returns FALSE.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Hi all, i am reading a file with help of CStdioFile using while loop and read the file till file reached end of file,in the file somewhere symbol exist,when reading this line with ReadString ,while loop becomes infinite loop and not return and application goes in notresponding state. please tell me how can i read the full file with this symbol or how can i remove this symbol from file before reading the file. thanks in advance.
There are several issues with what is going on here.. After looking the code its important to note the file.end is not doing what you want it to do. If you look at the definition of the data member it is returning an enumeration to the end of the file. It is not whether or not you are currently at the EOF. Also the methods you are using STOP on a EOF character because you are reading in the default text mode. You should be opening the file in binary read mode " CFile::typeBinary". Because of the special characters I would suggest that you tseek the end of file get the length of the file and then do a for loop to retrieve the data out of the file.
-
There are several issues with what is going on here.. After looking the code its important to note the file.end is not doing what you want it to do. If you look at the definition of the data member it is returning an enumeration to the end of the file. It is not whether or not you are currently at the EOF. Also the methods you are using STOP on a EOF character because you are reading in the default text mode. You should be opening the file in binary read mode " CFile::typeBinary". Because of the special characters I would suggest that you tseek the end of file get the length of the file and then do a for loop to retrieve the data out of the file.
Dear SnowHow, i have observe same result.