|
When using already existing container types from the STL, just use the container type as template parameter. You can retrieve the element type with the internal type definition value_type like this:
template <class Container>
istream& operator>>(istream& my_istream, Container& v)
{
typedef typename Container::value_type T; ...
If you define your own container type, you can do it in the same way. You just have to make sure your container type does define value_type :
template <class Element>
class MyContainer {
public:
typedef Element value_type;
...
P.S.:
IIRC STL containers already do have overrides for operator>>. You could save yourself some effort by just overriding this operator for your base type:
template <class T>
istream& operator>>(istream& my_istream, T& value) {
... It should work just as well as the above solution.
P.P.S.:
As it turns out I was wrong. There are no default implementations of operator>> for containers.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
modified 1-Sep-20 12:11pm.
|
|
|
|
|
char a, b;
printf ("write two letters")
scanf("%c %c", &a,&b);
printf("%c %c",b, a );
return 0;
when I run the program and press x and y for example y disappears when I use printf
|
|
|
|
|
Could you copy and paste the code you're running? What you've posted won't compile.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Works fine after fixing the missing semi-colon.
|
|
|
|
|
Is that a space in the middle of your scanf format? If so, you need to type “x(space)y”.
Mircea
|
|
|
|
|
No, it works with or without the space.
|
|
|
|
|
Apart from the missing semi-colon at the end of the first printf statement, the code works fine.
|
|
|
|
|
Programming... Backtracking.
I need help with backtracking question.
In an election, five parties won and got
A 20
B 14
C 30
D 16
E 40
In order to rule, a coalition of More than 60 must be negotiated. But we have restrictions:
A does not sit with D
C does not sit with E
A B C D E
A. 1 1 1 0. 1
B. 1 1. 1 1. 1
C. 1 1. 1 1. 0
D 0 1. 1 1. 1
E. 1. 1. 0. 1. 1
The function should return the number of possible coalitions.. Which is 3.
As soon as the coalition is formed, no need to add more parties.
A + E + B is not valid
|
|
|
|
|
Is there a specific issue? Could you post the code that you have tried?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Exactly what help do you need?
|
|
|
|
|
vafoqome wrote: A + E + B is not valid
Is that an additional restriction? This combo looks perfectly valid to me - it fullfils all the requirements.
As for backtracking, there's plenty of literature on that topic, and I'm sure lots of example codes as well.
Other than that, what is your question?
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
vafoqome wrote: I need help with backtracking question.
Helping you is not solving the problem for you.
Show your work so far, and explain problem you encounter.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Hi.
Please help me.
First of all, I hope you understand that the sentence structure can be strange as I ask questions using a translator machine.
I am developing a mini filter driver that prohibits reading from drivers other than the local disk drive.
However, IRP_MJ_CREATE does so much.
For example, it is also used to create volume drives the moment I open Explorer.
I don't want IRP_MJ_CREATE to be used when volume drives are created the moment I open Explorer.
Currently, I have registered IRP_MJ_CREATE in preOperation.
In the preOperation function, if it is not a local disk drive,
Data->IoStatus.Status = STATUS_NO_SUCH_PRIVILEGE;
Data->IoStatus.Information = 0;
It has been coded to make this work work.
Then, the moment I turned on Explorer, even the volume drives other than the local disk drive became inaccessible.
The first thing I want is that when Explorer opens, the volume drive will show up as accessible just like a local drive.
Second, I want files to be prevented from being read (prohibited to execute) when entering the volume drive.
I think the words are simple, but I think you need advanced technology. Still, I would be grateful for any help.
Thank you.
|
|
|
|
|
Hi,
I have not worked with mini filter drivers for about six years. But here are some things I think may help:
1.) In your PFLT_PRE_OPERATION_CALLBACK[^] callback you should probably allow anything originating from kernelmode to pass through. You can do this with ExGetPreviousMode[^] which will return KernelMode for file operations originating from the Windows kernel.
2.) After you have allowed kernelmode file operations to pass unmolested you can get the process ID of the usermode process performing the i/o with PsGetCurrentProcessId[^] and filter out whatever you want to pass through.
I don't normally send anyone away from codeproject.com but since I know that at least half of the Devices and Drivers team are active on the site I will defer you over to the NTFSD forum over at community.osr.com[^] where they are working with minifilters on a daily basis.
Best Wishes,
-David Delaune
|
|
|
|
|
Oh, thank you so much for the answer.
There is still a lot to learn about the mini filter, so it is difficult to say it, but I will find it and try it.
And thank you for telling me a good site.
Thanks a lot.
|
|
|
|
|
Hi,
I see that you have posted an entirely different question on the OSR website. You are now asking how to filter out directories.
You can use the FltIsDirectory function[^] to check if the file object is a directory.
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you for answer.
It takes some time to write the answer using a translation machine lol.
The article I wrote is correct.
I thought the text I wrote here was a bit ambiguous, so I made some corrections to write it.
Ultimately, What I have to do control what files(directories) are read (run) and written(modified, deleted) in usb drive, cd-rom drive, portable drive etc except for local drive(e.g. C drive D drive).
However, if I post too many questions at once, I don't think I can get a proper answer, so I started posting questions like this.
I think the question I posted here must have been a little bit more stranger than that on the osr website.
First of all, I want to do anything, whether I am blocking reading or writing, but I can't get a starting point.
There are many things that create something in the samples provided by Microsoft, but nothing prevents it.
Is there anything you can do to help?
I am waiting for your answer.
|
|
|
|
|
Member 14872681 wrote: Is there anything you can do to help? I am waiting for your answer. If you ask a very specific question (narrow in scope) you will probably get an answer.
Member 14872681 wrote: First of all, I want to do anything, whether I am blocking reading or writing, but I can't get a starting point. Most of the minifilter samples are located here: File system driver samples[^]
There are probably over a dozen more minifilter samples in older versions of the Windows DDK if you have them. Unfortunately I don't think they are being distributed anymore.
The code samples are a good place to start.
Best Wishes,
-David Delaune
|
|
|
|
|
Hi
Okay, I'm understand your reply.
Let's start with a sample.
I think I'm going to post a question while working on it, but if you see my article and have something helpful, please answer me.
Thank you.
|
|
|
|
|
Member 14872681 wrote: However, if I post too many questions at once, I don't think I can get a proper answer, so I started posting questions like this.
That is a good approach. The more you put into a single question, the more time it takes for everyone to read, and the less likely it is you will get a useful answer.
However, it wouldn't hurt to mention that you are working on a larger problem and point to the related posts you made, so anyone willing to help can get a better look at the whole picture.
Also, I like how you approach the translation. You keep sentences short and concise, that makes it harder for the translation engine to mess up the meaning.
(Sorry, I can't help with your problem. But I still felt that it's worth congratulating you on doing a good job asking questions - that is a rare skill nowadays!)
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
I am trying out VirtualDisk APIs, So far I am able to Open a VHDX file, get some of the properties by using GetVirtualDiskInformation. But I am not able to get RCT information and ChangedAreas.
1)Opendisk is done with VIRTUAL_DISK_ACCESS_GET_INFO flag.
2)GetVirtualDiskInformation
a. Works fine when version flag is set to GET_VIRTUAL_DISK_INFO_SIZE, able to fetch sector size and other information
b. Gives ERROR_INSUFFICIENT_BUFFER(122) when version flag is set to GET_VIRTUAL_DISK_INFO_CHANGE_TRACKING_STATE to access diskInfo->ChangeTrackingState.MostRecentId
PGET_VIRTUAL_DISK_INFO diskInfo;
ULONG diskInfoSize = sizeof(GET_VIRTUAL_DISK_INFO);
std::wcout << "size of diskinfo structure " << diskInfoSize << std::endl;
diskInfo = (PGET_VIRTUAL_DISK_INFO)malloc(diskInfoSize);
diskInfo->Version = GET_VIRTUAL_DISK_INFO_SIZE;
res = GetVirtualDiskInformation(vhdHandle, &diskInfoSize, diskInfo, NULL);
long physicalSize = diskInfo->Size.PhysicalSize;
long virtualSize = diskInfo->Size.VirtualSize;
long sectorSize = diskInfo->Size.SectorSize;
long blockSize = diskInfo->Size.BlockSize;
std::wcout << "physicalSize :" << physicalSize << std::endl;
std::wcout << "virtualSize :" << virtualSize << std::endl;
std::wcout << "sectorSize :" << sectorSize << std::endl;
std::wcout << "blockSize :" << blockSize << std::endl;
diskInfo->Version = GET_VIRTUAL_DISK_INFO_CHANGE_TRACKING_STATE;
res = GetVirtualDiskInformation(vhdHandle, &diskInfoSize, diskInfo, NULL);
std::wcout << "\nrct id:" << diskInfo->ChangeTrackingState.MostRecentId << std::endl;
3)queryChangesVirtualDisk gives ACCESS DENIED.
ULONG64 byteOffset = 0L;
ULONG64 byteLength = 19327352832;
QUERY_CHANGES_VIRTUAL_DISK_RANGE* changedAreas = NULL;
ULONG rangeCount = 0L;
ULONG64 processedLength = 0L;
res = QueryChangesVirtualDisk(vhdHandle, "rctX:c2eb01d9:ccb1:405d:acb6:f0e76d055906:00000001",
byteOffset, byteLength,
QUERY_CHANGES_VIRTUAL_DISK_FLAG_NONE,
changedAreas, &rangeCount, &processedLength);
Can someone please give some ideas on what I am doing wrong?
|
|
|
|
|
Quote: This value is not supported before Windows 10 and Windows Server 2016.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi Gerry,
I am trying in a Windows2016 hyperV, and guest VM has windows 10.
Also, I am able to get changed blocks by using WMI queries.
But VHD API is giving ACCESS_DENIED_ERROR.
Regards,
Hari
|
|
|
|
|
The first thing I'd do is confirm "without" a VM. And then I'd try Oracle's VmBox. Then try running as "admin" in the VM, etc.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi,
I do see at least one problem in your code:
ULONG diskInfoSize = sizeof(GET_VIRTUAL_DISK_INFO); should be changed to:
ULONG diskInfoSize = sizeof(GET_VIRTUAL_DISK_INFO) + sizeof(GUID);
cazorla19 wrote: queryChangesVirtualDisk gives ACCESS DENIED. Could you show me the flags you are passing to OpenVirtualDisk?
Best Wishes,
-David Delaune
|
|
|
|
|