flockfile and funlockfile problems

I want to affix password while open my file.But flockfile and funlockfile funcs is not working.They were not declared
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <windows.h>
#include <sys/locking.h>

using namespace std;
int main(){
char realpass[ ]="a",*pass;
cout<<"U entry password for Pass.txt to open: ";
cin>>*pass;
fstream file;
file.open("Pass.txt");
flockfile(file);
if(realpass!=pass){
cout<<"Sorry,wrong pass";
Sleep(5000);
exit(1);
}
else{
funlockfile(file);
system("Pass.txt");
}
file.close();
return 0;}


And i am using Code Blocks.
You really don't need to use sheep file and the fun version... the C standard library does it for you 'under the hood'. See http://linux.die.net/man/3/flockfile

Another problem is that you are trying to mix C++ and C I/O. A C++ std::iostream is not a C FILE*. The f[un]lockfile() functions only work on a FILE*.


Also, the f[un]lockfile() functions are for handling multiple threads in file accesses... Are you sure you aren't trying to open your file in exclusive access mode instead?
I am learning c++ Duoas.And trying myself.I didn't open this hood in article or lounge section.This section's name beginner.What is the mean beginner?Ok?Thank u for help.
I am aware of that and have given you a very kind answer, complete with links to the answer to your question. I've also been kind enough to recognize that you are probably using the wrong function for what you want to do, and I've asked for more information in order to help you better.

But if you are going to become rude then get lost.
http://www.cplusplus.com/forum/beginner/37099/
Remember this.I know.I said thank u.I am not a thankless man.But u said:You really don't need to use sheep file and the fun version.Where are u know need or don't need?I asked u.Yes.I don't need this codes.But i want to this language.So i must try myself.I accepted i am a beginner programmer.But sheep,fun and kind words to impropered to say.I feel have been u are a good man.But if u are a going to become scathing man then get lost Duoas.
But sheep,fun and kind words to impropered to say.
I've said nothing improper to you, but I refuse to be abused after kindly offering free help. BTW, the part about sheep is called humor, as in "a flock of sheep in a file". Good luck playing with the big boys when you assume you know as much as they do...

then get lost Duoas.
OK. You're now on my personal ignore list.
U have be adroid man!!!My english is bad.So u apprehended me.U exclude in this forum utmost.
I want to say this:then get lost.I want to call u.Probably,I must said:then get lost,Duoas.Wrong mean.I don't want then get lost Duoas.
Last edited on
Topic archived. No new replies allowed.