Two points about ur program:
1. Dont flush the input stream because it has got undefined behaviour.
2. YOu are assigning the char array "okay" to char pointer stuff but till that point okay has not been defined. Swap the two stmts to avoid the syntax error.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
for (x=0; x <strlen(pword); x++)
{
file2.open(fname, ios::in);
file2.getline(stuff, 3);
file2.close();
cout << (char)okay;
}
What the H is the above supposed to do? What itIS doing is opening a file, reading the first line, the closing the file -- all that possibly hundreds of times (depending on length of pword). Why in the world would you want to waste so much CPU time doing the same identican thing so many times?
You are obviously writing a c++ program. Then why are you using C style character arrays instead of c++ std::string class? There are valid reasons for doing it, but I don't see any valid reasons in your program, unless of course (1) your instructore required it, or (2) you have not learned about std::string yet.
std::string uname;
std::string pword;
std::string fname;
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
I am using char arrays, because in the file i/o procedures, char arrays are required, and because I am typecasting them from char to int and you cannot typecast std::string, at least not in VC.NET.
depends. please post an example of what you mean -- there may be other better or more appropriate alternatives.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
In the first chase y is just one single character, in the second case it is a string. This is not an example of what I was thinking about and you would be better off leaving it the way you have it. Something like below is what I was thinking
char buf[255];
in.read(buf,sizeof(int));
int x = *(int*)buf;
above could be rewritten like this, but I'm sure you probably already know that.
int x;
in.read(&x,sizeof(int);
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343