|
A couple of things to consider...
- why are you calling open()? It's more common to see something like:
std::ifstream input( "c://test.txt" );
if( input )
{
std::string text;
std::getline( input, text );
}
- Don't bother manually closing the file - it's completely pointless
- Are you sure you want to read one character from a file then try and write 150? Especially into something that's a constant block of memory.
None of these things explain why the file isn't being opened. The Error number you're getting seems to imply the file already exists which is an error I'd expect from trying to open an ofstream. Are you doing the GetLastError immediately after calling myfile.open()?
Cheers,
Ash
|
|
|
|
|
T.RATHA KRISHNAN wrote: std::string filename = "E://Work//Data//playerdata.txt";
Try:
std::string filename = "E:/Work/Data/playerdata.txt";
or
std::string filename = "E:\\Work\\Data\\playerdata.txt";
"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
|
|
|
|
|
Hello,
I'm using a small program that notify me when a file size change inside a directory. The program worked perfect under Win XP, now in Windows 7 the size changes are ignored for long periods and notifications are not in sync with the changes.
At first glance that could be seen as something related to caching/flushing differences between XP and Win 7 but I verified that the file I'm monitoring is being flushed to the disk and is not staying in cache.
I used the command tail -f monitoredfile.txt displaying the file content as it is updated and I was able to see all the changes in real time but my monitor program wasn't reporting any file size change.
This is the monitor program:
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <tchar.h>
void RefreshDirectory(LPTSTR);
void RefreshTree(LPTSTR);
void WatchDirectory(LPTSTR);
int _tmain(int argc, TCHAR *argv[])
{
if(argc != 2)
{
_tprintf(TEXT("Usage: %s <dir>\n"), argv[0]);
return 1;
}
WatchDirectory(argv[1]);
}
void WatchDirectory(LPTSTR lpDir)
{
DWORD dwWaitStatus;
HANDLE dwChangeHandles[2];
TCHAR lpDrive[4];
TCHAR lpFile[_MAX_FNAME];
TCHAR lpExt[_MAX_EXT];
_tsplitpath_s(lpDir, lpDrive, 4, NULL, 0, lpFile, _MAX_FNAME, lpExt, _MAX_EXT);
lpDrive[2] = (TCHAR)'\\';
lpDrive[3] = (TCHAR)'\0';
dwChangeHandles[0] = FindFirstChangeNotification(
lpDir,
FALSE,
FILE_NOTIFY_CHANGE_SIZE);
while (TRUE)
{ printf("\nWaiting for notification...\n");
dwWaitStatus = WaitForMultipleObjects(1, dwChangeHandles, FALSE, INFINITE);
switch (dwWaitStatus)
{
case WAIT_OBJECT_0:
_tprintf(TEXT("Directory (%s) changed.\n"), lpDir);
if (FindNextChangeNotification(dwChangeHandles[0]) == FALSE)
{
printf("\n ERROR: FindNextChangeNotification function failed.\n");
ExitProcess(GetLastError());
}
break;
default:
printf("\n ERROR: Unhandled dwWaitStatus.\n");
ExitProcess(GetLastError());
break;
}
}
}
|
|
|
|
|
It probably is a permission issue.
Try running the program from an elevated command prompt.
|
|
|
|
|
I tried with UAC OFF and ON, running as admin, etc. it's more related to a caching issue I guess. In the meanwhile I found a turnaround that made it work, I run a script on the background that apply the touch command every 100ms or so to the file I'm monitoring, it seems it forces a flush and then the changes are detected by my program...
Maybe that will give more clues to find a better solution.
Thanks,
|
|
|
|
|
Does argv[1] refer to a remote computer? Do you have the "backup file and directories" privilege?
"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
|
|
|
|
|
argv1 refers to the directory you want to monitor i.e. monitor c:\tmp
|
|
|
|
|
auriga19 wrote: argv1 refers to the directory you want to monitor i.e. monitor c:\tmp
I'm full aware of that. When FindFirstChangeNotification() fails to receive notification, does argv[1] refer to a remote computer?
"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, it refers to a directory on the local computer.
|
|
|
|
|
Ok, then the redirector is likely not the problem.
Just for grins, did you enable the "backup file and directories" privilege?
"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
|
|
|
|
|
I just checked, I have those privileges enabled.
|
|
|
|
|
We can HOOKAPI. Such as "MessageboxA / W" or "OpenProcess" and so on. Then we can Hook the other?
For example,Hook "PEXCEPTION_POINTERS"?
<br />
LONG WINAPI VectoredExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo)<br />
//This is our definition of the function,This is an internal function and Not exported.It isn't API HOOK it so we can not have any way to HOOK PEXCEPTION_POINTERS?
If it can, then how to write?
|
|
|
|
|
You want to hook 004381230 right?
Actually API hooking technique is for hooking APIs. I dont think PEXCEPTION_POINTERS can be hooked.
If tell ur need, may be i can help u.
Величие не Бога может быть недооценена.
|
|
|
|
|
Does "004381230" mean?
|
|
|
|
|
I have a multidoctemplate app, call it MyApp. For the default doc-view-frame of MyAppDoc-MyAppView-CChildFrame, I override the frame ActivateFrame to show the frame maximized. I added another doc-view-frame set, NewDoc-NewView-NewFrame, NewFrame derived from CMDIChildWnd. I override NewFrame ActivateFrame to show it normal. When I create and show a NewDoc object, it displays correctly but now my MapAppView is no longer maximized but cascaded with the NewView object. Why would anything I do with NewView affect anything I had done with MyAppView? I want MyAppView to continue to be maximized but NewView to be normal since I may create a lot of NewView objects and I want them cascaded when they are first shown. Thanks in advance.
|
|
|
|
|
That's the default behavior/implementation. If one child frame is maximized, so are the others when activated.
If you want one child frame maximized while the others are not, you will have to make it happen yourself. One suggestion would be to intercept the message when the user maximizes the window and then just resize it to the size needed and remove borders and other window decorations by modifying the window style. There are some things to take care of though, like when the main frame size changes, so should the 'maximized' child frame.
|
|
|
|
|
Thank you for the response. I tried that by overriding OnSize in both the child frame I want to keep maximized and the others I want to cascade. But the ones I want to cascade still come up maximized. I'll keep fiddling around with it.
|
|
|
|
|
Hello, id like to connect to a http server, preferably in a multiplatfrom working way so the code will work on linux and windows, a windows only way is fine for now aswell i guess (c/c++ only).
After the connection is established i want to check if a file exists.
Open for any function recommendations /papers etc.
Just anything.
Thanks.
modified on Wednesday, June 30, 2010 11:49 AM
|
|
|
|
|
A non-portable way might be to use URLDownloadToFile() . You might also check the socket API.
"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
|
|
|
|
|
A portable solution would be using one of the many C++ networking libraries offering a "HTTP client". Checking if a file exists is as simple as making a HTTP request and see if something else than status code 200 is returned, strictly speaking 404 means file not found.
/M
|
|
|
|
|
I'd suggest cURL http://curl.haxx.se/[^], or rather the libcurl bit of it. Works on Windows, Linux, FreeBSD, OS/X and Solaris and those are just the platforms I've used it on.
Cheers,
Ash
|
|
|
|
|
Hi sir,
I want to draw a circle.
Any link or any sample will be helpful
Thanks
Raj
|
|
|
|
|
Have a look at CDC::Ellipse [^] or Ellipse [^] (there's also an example [^]).
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]
|
|
|
|
|
If you're trying to draw directly into a bitmap (or similar) then you need to look at the equations for a circle.
In the simplest form, you can find points on the circumference by using :-
x = r * cos(angle);
y = r * sin(angle);
for various values of angle.
Days spent at sea are not deducted from one's alloted span - Phoenician proverb
|
|
|
|
|
Hi!
I've to read a particular line from a file. My .txt file has 55 lines. I've to read any particular line and store the contents of eache line to a structure. The file contents are separated by commas. How to do this?
|
|
|
|