|
Hi
I am using CFile to implement my IO. But in the middle of reading/writing, I need to read/write a bitmap to the file. Is there a way convert a CFile object to a "istream" object?
Thanks,
|
|
|
|
|
Why do you want to convert to istream ?
You can use the Read /Write methods of CFile to write the bitmap to the file.
The file must of course be open in binary mode.
|
|
|
|
|
Thank you for your reply.
I need to construct a DIB BITMAP which constructor uses a "*pIStream" as parameter.
I might be able to read data into a string buffer.
Thanks,
|
|
|
|
|
May be you can take a look at SHCreateStreamOnFile() API.
|
|
|
|
|
I'm curious to know if having a small number of .mdb databases connections open at the same time will tax systems or if it's ok to do assuming they are only open for a brief instant in time.
Details:
For applications that briefly open an .mdb file while initializing, I normally try to pass a reference to an instance of CDatabase that has been opened on a database while loading data from tables. I'll usually close the database connection once I know I'm done. The database remains open for less than a second.
I'm now faced with the need to read from multiple .mdb files while initializing, with no guaranteed order, and the potential to need to alternate reads between the databases. I've noticed that there is a big time difference if I close the old database connection and open a new one when I need to switch which database I'm reading from.
My intention is to keep a small array of those open database connections to keep the duration of the loading time to a minimum and close them promptly once I'm done.
Are there any hidden "gotchas" to doing this? Is it unwise to keep more than one instance of a database open at a time?
|
|
|
|
|
Well, after benchmarking many combinations using multiple .mdb files, this does not affect performance or memory usage in any significant way.
(For anyone who might stumble upon my question and wonder how this ended up)
|
|
|
|
|
Hi all,
I got a txt file filled with HTML code extract from www.finance.yahoo.com
this is the data from finance.yahoo.com
Dow 10,212.73 +27.20 +0.27%
Nasdaq 2,174.00 +2.80 +0.13%
10 Yr Bond(%) 3.6500% -0.0400
Oil 75.25 +0.82 +1.10%
Gold 1,113.60 +10.10 +0.91
the 3 values i wanna extract from each stock is all the values above. all the values need to be read from the HTML text file of finance.yahoo.com.
so, how should i create the method and what parameter should i pass in?
should i create individual method for each stock? example
double getDOW(param1, param2, param3, etc)
or a generic method that can search any stock quote
|
|
|
|
|
Use getline or CStdioFile to read the file line by line.
Then use strtok_s or CString::Tokenize to extract the values from each line.
|
|
|
|
|
You can have one method to read the "raw" data for each data line as long as they follow the same pattern, for example, in your case, it looks like:
<name> <data1> <data2> <data3>
after that, you have to interpret each data like depending on where it comes from, is it from Dow ? is it from "Oil"? and decide if it's a percentage, a absolute value, a "delta" and put those values in the appropriate fields in your application :
if ( <name> == Dow )
{
...
}
else (if <name> == Nasdaq )
{
...
}
...
Technically, there must be dozen different ways to do that, but I try to keep it as simple as possible.
Good luck with that.
This signature was proudly tested on animals.
|
|
|
|
|
benjamin yap wrote: all the values need to be read from the HTML text file of finance.yahoo.com.
Use the IHTMLDocument interface to navigate the HTML.
Did you read this article suggested to you three days ago?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
how do i extract 2,190.06 from here?
<span class="streaming-datum" id="yfs_l10_^ixic">2,190.06</span>
The ihtmldocument quite complicated to understand
|
|
|
|
|
benjamin yap wrote: how do i extract 2,190.06 from here?
Look for a SPAN element named yfs_l10_^ixic. Then use one of the innerText , outerText , innerHTML , or outerHTML properties.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
do i have to
#include anything to use the innertext, outertext etc etc?
|
|
|
|
|
They are methods of the IHTMLElement interface. You might need to include mshtml.h .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
#include <iostream>
#include <fstream>
using namespace std;
int main() {
fstream file("c:\\test.txt",ios::in | ios::out | ios::binary);
if(file.is_open())
{
file<<"Hello";
file.close();
}
else
{
cout<<"Error";
}
return 0;
}
I wonder why this code is giving me the output "Error" unexpectedly...what went wrong in this code. I'm not able to write texts in file..please help
|
|
|
|
|
As you may check, opening the file with ios::in flag set, fails if the file doesn't exist.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Member 6910300 wrote: I'm not able to write texts in file..please help
Does the file exist?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
no the file is expected to be created.
in the following case also it outputs "Error"
fstream file("c:\\test.txt",ios::out | ios::in);
if(file.is_open())
{
file<<"Hello";
file.close();
}
else
{
cout<<"Error";
}
|
|
|
|
|
Then you should use:
ofstream file("c:\\test.txt", ios::binary);
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
thanks for the answer but i dont want to use ofstream and ifstream class instead i want to use fstream class only. Is it possible? and i also need the file to be created as using ofstream.
|
|
|
|
|
if the file does not exist, you have to use
fstream file("c:\\test.txt", ios::out | ios::binary);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
what's problem with this bit masking
ios::in | ios::out | ios::binary
since we have specified out in the mask, why the file is not being created.
thanks for replying.
|
|
|
|
|
The problem is you can't read from a not exitsting file, I suppose.
Your bit mask works if the file do exist. On the other hand, if the file does not exist you should use the
ios::out | ios::binary
mask.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
maybe your file doesn't exist.check your file. I check your code, is ok.
Calvin
|
|
|
|
|
Hi,
I am using ON_WM_KEYDOWN event for keyboard shortcuts in my application. And below is function to handle this keydown action.
void CRearPanel::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(nChar == 112)
{
if(((CMainFrame*)AfxGetMainWnd())->GetRearPanel()->m_hWnd != NULL)
((CMainFrame*)AfxGetMainWnd())->GetRearPanel()->ShowWindow(SW_HIDE);
if(((CMainFrame*)AfxGetMainWnd())->GetHWSimulatorDlg()->m_hWnd != NULL)
((CMainFrame*)AfxGetMainWnd())->GetHWSimulatorDlg()->ShowWindow(SW_HIDE);
}
else if(nChar == 113)
{
((CMainFrame*)AfxGetMainWnd())->OnViewHWSimulator();
if(((CMainFrame*)AfxGetMainWnd())->GetRearPanel()->m_hWnd != NULL)
((CMainFrame*)AfxGetMainWnd())->GetRearPanel()->ShowWindow(SW_HIDE);
}
else if(nChar == 114)
{
((CMainFrame*)AfxGetMainWnd())->OnViewRearpanel();
::SetFocus(((CMainFrame*)AfxGetMainWnd())->GetRearPanel()->m_hWnd);
if(((CMainFrame*)AfxGetMainWnd())->GetHWSimulatorDlg()->m_hWnd != NULL)
((CMainFrame*)AfxGetMainWnd())->GetHWSimulatorDlg()->ShowWindow(SW_HIDE);
}
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
Now let me explain my problem,
Here I am having one main document window which is coming up initially. And I have another 2 dialog window which should be open on keydown event. From main document window I am able to get key down event and functionality working properly. In Those 2 dialog I put same events, and there start my problem. First time when it(dialog) comes up its not catching keydown event. If I close that dialog and then open it again then I am able to catch it. I found on net some where to put below code,
BOOL CRearPanel::PreTranslateMessage(MSG* pMsg)
{
if( pMsg->message == WM_KEYDOWN )
{
::TranslateMessage(pMsg);
::DispatchMessage(pMsg);
return (1);
}
return CDialog::PreTranslateMessage(pMsg);
}
But I dint find it helpful. Can any one help me for this issue.
|
|
|
|