Serialization & Reading/Write Multiple Lines :: MFC
-
Hello. My intention is to read each line from a file and save it into a STL list of CString. So if there are 10 lines in the file, then the linked list of CString will be of size ten. Prosise demonstrates a very effective way to read and write from and to a file linewise using the CStdioFile class. However, in doc/view, MFC turns to Serialization. The problem, to me, with Serialization is I do not know what is going on in the background. I do not know what the framework does to the data in terms of CArchive. When writing to CArchive, I use this: for (iter = list.begin(); iter != list.end(); ++iter) ar << *iter; I am not sure how to read data from CArchive back into the linked list. First, I do not know whether data is stored similar to a file, i.e. if you write line1 and line2, then you can read back line1 and line2 in its original form. How should I go about read data from CArchive back into the linked list if I have no knowledge of how CArchive manages the orientation of the data? For example let say that the linked list of CString has this: ----- a b c d e ----- Okay. When it stores the data into CArchive, I assumpt it stores it like this: <- a <- b <- c <- d <-e However, if I have no prior knowledge of what was in the CArchive, how do I go about saving the data from CArchive back into the linked list? Thanks, Kuphryn Note: If nothing works, I think the technique Prosise shows is best since class CStdioFile features ReadString() and WriteString().
-
Hello. My intention is to read each line from a file and save it into a STL list of CString. So if there are 10 lines in the file, then the linked list of CString will be of size ten. Prosise demonstrates a very effective way to read and write from and to a file linewise using the CStdioFile class. However, in doc/view, MFC turns to Serialization. The problem, to me, with Serialization is I do not know what is going on in the background. I do not know what the framework does to the data in terms of CArchive. When writing to CArchive, I use this: for (iter = list.begin(); iter != list.end(); ++iter) ar << *iter; I am not sure how to read data from CArchive back into the linked list. First, I do not know whether data is stored similar to a file, i.e. if you write line1 and line2, then you can read back line1 and line2 in its original form. How should I go about read data from CArchive back into the linked list if I have no knowledge of how CArchive manages the orientation of the data? For example let say that the linked list of CString has this: ----- a b c d e ----- Okay. When it stores the data into CArchive, I assumpt it stores it like this: <- a <- b <- c <- d <-e However, if I have no prior knowledge of what was in the CArchive, how do I go about saving the data from CArchive back into the linked list? Thanks, Kuphryn Note: If nothing works, I think the technique Prosise shows is best since class CStdioFile features ReadString() and WriteString().
If you store data in a CArchive like ar << line1; ar << line2; then you can safely read it like ar >> line1; ar >> line2; So to read data from the Archive use: CString a; ar << a; mylist.push_back (a); If you are not sure what is is in the archive then there may be o problem... Actually this is a more general problem. How can you read from a file if you are not sure what it's in it? Best regards, Alexandru Savescu
-
If you store data in a CArchive like ar << line1; ar << line2; then you can safely read it like ar >> line1; ar >> line2; So to read data from the Archive use: CString a; ar << a; mylist.push_back (a); If you are not sure what is is in the archive then there may be o problem... Actually this is a more general problem. How can you read from a file if you are not sure what it's in it? Best regards, Alexandru Savescu
Thanks! You cleared up some of my confusion. The datafile my program read/write has a certain data format. I read the data in line by line. I am intrigued about reading data from a *line by line* when you do not know its content too. Maybe someone can add to that. Thanks, Kuphryn
-
Hello. My intention is to read each line from a file and save it into a STL list of CString. So if there are 10 lines in the file, then the linked list of CString will be of size ten. Prosise demonstrates a very effective way to read and write from and to a file linewise using the CStdioFile class. However, in doc/view, MFC turns to Serialization. The problem, to me, with Serialization is I do not know what is going on in the background. I do not know what the framework does to the data in terms of CArchive. When writing to CArchive, I use this: for (iter = list.begin(); iter != list.end(); ++iter) ar << *iter; I am not sure how to read data from CArchive back into the linked list. First, I do not know whether data is stored similar to a file, i.e. if you write line1 and line2, then you can read back line1 and line2 in its original form. How should I go about read data from CArchive back into the linked list if I have no knowledge of how CArchive manages the orientation of the data? For example let say that the linked list of CString has this: ----- a b c d e ----- Okay. When it stores the data into CArchive, I assumpt it stores it like this: <- a <- b <- c <- d <-e However, if I have no prior knowledge of what was in the CArchive, how do I go about saving the data from CArchive back into the linked list? Thanks, Kuphryn Note: If nothing works, I think the technique Prosise shows is best since class CStdioFile features ReadString() and WriteString().
Wouldn't it be easier (if it's possible in your app) to use a CStringList or CStringArray and serialize that one, using CStringList::Serialize or CStringArray::Serialize? (Just a thought) -- Alex Marbus www.marbus.net But then again, I could be wrong.
-
Hello. My intention is to read each line from a file and save it into a STL list of CString. So if there are 10 lines in the file, then the linked list of CString will be of size ten. Prosise demonstrates a very effective way to read and write from and to a file linewise using the CStdioFile class. However, in doc/view, MFC turns to Serialization. The problem, to me, with Serialization is I do not know what is going on in the background. I do not know what the framework does to the data in terms of CArchive. When writing to CArchive, I use this: for (iter = list.begin(); iter != list.end(); ++iter) ar << *iter; I am not sure how to read data from CArchive back into the linked list. First, I do not know whether data is stored similar to a file, i.e. if you write line1 and line2, then you can read back line1 and line2 in its original form. How should I go about read data from CArchive back into the linked list if I have no knowledge of how CArchive manages the orientation of the data? For example let say that the linked list of CString has this: ----- a b c d e ----- Okay. When it stores the data into CArchive, I assumpt it stores it like this: <- a <- b <- c <- d <-e However, if I have no prior knowledge of what was in the CArchive, how do I go about saving the data from CArchive back into the linked list? Thanks, Kuphryn Note: If nothing works, I think the technique Prosise shows is best since class CStdioFile features ReadString() and WriteString().
This article may help. /ravi
-
Wouldn't it be easier (if it's possible in your app) to use a CStringList or CStringArray and serialize that one, using CStringList::Serialize or CStringArray::Serialize? (Just a thought) -- Alex Marbus www.marbus.net But then again, I could be wrong.