Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Visual-Studio MFC file Treeview , +
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 25-Mar-13 2:33am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^].
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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 .. :(
  Permalink  
Comments
Richard MacCutchan at 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 at 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 at 27-Mar-13 4:44am
   
Not so difficult was it?
mithun_linux at 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 at 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.
mithun_linux at 1-Apr-13 3:17am
   
Hi thanx a lot like now i have successfully created the application with your help. And i have one more question at you ... like after creation of a basic SDI app with "CTreeView" based class can we split the output window under he ame project for our requirement.???
Richard MacCutchan at 1-Apr-13 4:37am
   
Yes, take a look at the CSplitterWnd Class
mithun_linux at 1-Apr-13 4:52am
   
Thank you :)

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 269
1 OriginalGriff 240
2 CPallini 195
3 Maciej Los 177
4 BillWoodruff 173
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 25 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100