Click here to Skip to main content
15,886,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a text file with the follownd data
A-A1

In which A is the root and A1 is the child.
I need to create an MFC SDI Application to open the txt file and print the contents in the tree format like this
A
|_ A1

Since im a newbie in this i really dont know where to start like how to open a file in my application how to parse the data etc.
Any help is appreciated.
Thanks in advance.
Posted

Parsing the data is simply a matter of splitting your text into its constituent parts via a parser. You can either write your own, based on one of the many tokenizer functions, or you can implement a free third party parser. Creating the tree is similarly not too difficult as Windows has a built in tree control that is implemnted in MFC as the CTreeView Class[^]. There are also many sample projects around that can help with the basics; take a look at the articles section[^].
 
Share this answer
 
Since i have started jus two days back with Visual Studio .. i really dont know how that parsing works and where in and under in which function these are to be implemented because when i create a simple SDI application in the name of "new" there are many source files .. :(
 
Share this answer
 
Comments
Richard MacCutchan 25-Mar-13 9:23am    
Firstly: please do not post supplementary questions as solutions.
Secondly: this is not really a Visual Studio issue; it is a C++/Windows/MFC question. If you do not know how to use the base CRT or STL libraries in C/C++ then I suggest getting hold of a book, or looking at the MSDN reference pages. I would also suggest you start with a much simpler project until you are comfortable with the language; there are many samples and tutorials to be found here on CodeProject in the Articles section.
mithun_linux 27-Mar-13 3:17am    
CString pathname,strLine;
CStdioFile File;

if(File.Open(pathname, CFile::modeRead)) // Open file to be read
{

while(File.ReadString(strLine)) // Read file
{
int Position = 0;
CString Token;

Token = strLine.Tokenize(_T("-"), Position);
while(Token!="")
{
_tprintf_s(_T("Token: %s\n"), Token);
Token = strLine.Tokenize(_T("-"), Position);
}

This is wat i have written
Richard MacCutchan 27-Mar-13 4:44am    
Not so difficult was it?
mithun_linux 27-Mar-13 5:01am    
Nope it was not much difficuilt i learned and wrote it .. Thank you ...
in the above program the Position is set to 0 mens it points the first string and after the delimiter it tokenizes the 2nd and so on.
First it tokenizes "A" and that is root and second is "A1" that is child.
How to map the output of tokenizer function to treeview to be displayed?? Any comment on this part?
Richard MacCutchan 27-Mar-13 5:44am    
Use the CTreeView class as I suggested above, or format each line with leading spaces as defined by the value of Position. See also my answer to your further question on this subject.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900