|
I do it like this..
CString strBuff;
CFile file;
if(file.Open(_T("anyfile.dat"),CFile::modeRead))
{
char cBuf[2048];
UINT uBytesRead;
while(uBytesRead = file.Read(cBuf, sizeof(cBuf)-1))
{
cBuf[uBytesRead] = NULL;
strBuff += CString(cBuf);
}
file.Close();
...
}
else
{
}
Hope it helps
Rob
|
|
|
|
|
COOL, thank you very much!
now, i have another question:
my .txt looks like that:
1 2 3 4 10
4 6 23 11 66
my problem is, i don´t know the number of rows and columns. do you (or somebody else) know, how i can find that out inside the program?
Sunny
|
|
|
|
|
That would depend on what constitutes a column and a row, however the following would probably work.
each column is seperated by a space character ASCII (32) and each row is seperated by a carriage return (13) line feed (10).
Iterate your buffer and look for these characters and add a counter to track them, whola!!! You've calculated number of columns and rows...
p.s-This kinda sounds like a school project.
"No more answer for U" - Word Nazi
Cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
hi!
what do you mean with Iterate your buffer and look for these characters ? How can I do that?
it sounds like a school project but i finished school.
it`s a project for personal use, only. but at the moment i have no idea´s in this field of reading txt files.
thanks for everything
sunny
|
|
|
|
|
Iterate = repeat a task
buffer = temporary storage
You loaded your file into a CString buffer successfully and now it's time to iterate the characters in your buffer and count the CRLF and SPACE characters.
CFile myFile("myfile.txt", CFile::modeRead);
UINT nFileLen = myFile.GetLength();
const unsigned char* pTemp = new char[nFileLen+1];
memset(pTemp, 0, nFileLen+1);
myFile.Read(pTemp, nFileLen);
CString buff=pTemp;
for(int i=0; i<buff.GetLength(); i++){
if(buff.GetAt(i)==32)
nColumnCount++;
else if(buff.GetAt(i)==13 && buff.GetAt(i+1)==10)
nRowCount++;
}
delete[] pTemp;
Should give you rough idea as to how things are done
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
For some time now i been working on c++ and i just got to the point where i cant find anything on the subject i need.
Here is the problem
I want to add a command to the general contexmenue "the one when you right click on some file.some_extiention" Like winrar or winzip has it. the problem is that i don't want it just for some particular file exetion but for all extensions whenever it has an extension or not.
Like the open command,open with or the sendto command. Puting an enty on each file extension is not a solution so where do i find any exemples or help on this.
Thank you.
|
|
|
|
|
|
How can I tell the MFC CDialog class not to create the empty CControlBar* m_pWndEmptyCB under Embedded Visual C++ 3.0.
Is there any WS_??? or WS_EX_??? flag to tell the CDialog class with ModifyStyleEx not to create this empty CControlBar ?
--
Nice greets, Daniel.
|
|
|
|
|
Hi.
I would like to know what are some recommended advanced C++ book for both design and implementation including STL? I began learning C++ over a year ago and have been fasinated by C++ and its powerful OOP paradign since that time. I have studied these pure books.
- C++ How to Program by Deitel&Deitel
- The C++ Standard Library: A Tutorial and Reference
by Nicolai M. Josuttis
- Accelerated C++: Practical Programming by Example
by Andrew Koenig, Barbara E. Moo
- The C++ Programming Language (Special 3rd Edition)
by Bjarne Stroustrup
I am looking into books:
- Exceptional C++
- More Exceptional C++, Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library
- More Effective C++: 35 New Ways to Improve Your Programs and Designs
Thanks,
Kuphryn
|
|
|
|
|
Advanced C++ - Coplien
This book goes over many of the advanced idioms and design strategies that you can achieve using C++. Some of the things presented in here are old hat like reference counting (at least if you are familiar with COM). Other techniques are new and point out techniques that you do not think of every day.
There is a good apendix in Rector/Sells book ATL Internals for templates. The appendix goes over basic templates, then it describes how ATL is able to accomplish some of the amazing things that it does. I have used a few of these techniques myself. I think this is definetly worth checking out.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
|
The best place I can come to think of to find out about this FAQ is comp.lang.c++.moderated. Try searching it from groups.google.com and I'm sure you'll find answers from the best there is.
|
|
|
|
|
|
Okay. Thanks everyone.
I will buy the package at Amazon with Effective STL and Modern C++ Design. Amazon, through database statistics, have determine that readers prefer those two books together.
I am the kind of person who learn via practice and more important via experience. Thus I believe the two Effective C++ books will not as much because they will only "clear" up simple confusions rather than introduce more powerful software designs and implementions. I could ask members to help with all the small missing details.
Kuphryn
|
|
|
|
|
Hi,
In a dialog based application, i have a listbox used for show the
CD/dvd data, including address, hex value and assci. Now i want to
put the tooltip for each item data by using mouse action.
I known that how to select the row and put a tooltip text to it, but how to select the item in a line and put the tooltip text for each item?
Thanks in advance!
chen
|
|
|
|
|
What do you mean a line? Do you mean selecting an entire column? One solution is to just get the coordinate of the mouse pointer, traverse through the items in the listbox, and select one column item from every row.
Kuphryn
|
|
|
|
|
Hi Kuphryn,
Thanks for your reply. In fact, my data is shown as the data shown in
Cywin by jhd command. What i want is select two character each time and show the values (which row it hold, the corresponding dec, binary, and hex values).
My problem is how to select the "words" ?
The following are the data shown in listbox (a line/row)
Address : hex data : assci cod
00000010: 43 44 2D 42 52 49 44 47 45 20 20 20 20 20 20 20 : C D - B R I D G E
The 43 is what i want to selected "words" and then show
its related info in the tooltip.
Best Regards,
chen
|
|
|
|
|
Okay. IN the row with the HEX integers, are each word placed in a separate column? For example:
|43|44|2D|...
Kuphry
|
|
|
|
|
Yes, they are organized as you said.
like this:
43 44 2D 42 52 49 44 47 45 20 20 20 20 20 20 20
Also i want to show tooltip on these "words" only.
Tooltip shouldn't be shown the other items or text.
chen
|
|
|
|
|
Okay. Select the row of HEX integers and then the column of a specific HEX integer.
Look at NM_HOVER and LVN_HOTTRACT events. I am not familiar with handling events for mouse-hover in a CListCtrl. However, I believe the solution to your problem will require an event handler for the mouse-hover. In other words, you need to know what the user is pointing at in order to display the correct tooltip.
Kuphryn
|
|
|
|
|
I need to change the height of my CListCtrl when scrollbars are not present (horizontally). How can I , on the fly detect if the control has scrollbars or not? its columns keep changing so sometimes thee is a scrollbar, and sometimes not...
Thanks,
ns
|
|
|
|
|
One solution is to add messages handlers for both horizontal scroll bar and vertical scroll bar.
WM_HSCROLL - OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
WM_VSCROLL - OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
Kuphryn
|
|
|
|
|
Accumulate the width of each column. If the total exceeds the list control's client area's width, you've got scrollbars. Use GetColumn() to get the column widths and GetClientRect() to get the client rect.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Thanks for the ideas....its a funny problem. When there are sbars, I've shrunk the control down so all you see are the headers and the scrollbar. When there arent enough columns populated, the sb vanishes, and the area it took up, is visible to the user because now the first row of the control shows. I have to make it somehow that it doesnt get this blank area...only the header should show.
|
|
|
|
|
Hmm, you could try using one of SPI_ constants (none seemed obvious) in GetSystemMetrics() to get the height of the list control's header control, and use this value to resize the control.
Alternatively, you could just hide the list control and show a dummy one (of fixed height) with the same columns.
But if you want my honest opinion the concept of a list control that changes its height seems suspect at first glance.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|