Hi!
I have a strange problem with files. I used method .open() to open file, but I think it doesn't work. The code is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <fstream>
#include <string>
Using namespace std;
Int main (){
Fstream myfile;
String name,line;
Cin>>name;
myfile.open(name.c_str(), ios::out);
If (!myfile.is_open) return -1;
Else {
Cin>>line;
myfile<<line;
myfile.close();
}
Return 0;
}
It's good, compiler doesn't give me error, but program never opens file. I tried also to set a constant in function .open() ("name.txt") but it doesn't work. It doesn't give me -1, but it doesn't write (also open) file.
What kind of problem could it be?
You're missing the parens after myfile.is_open.
So instead of calling the function, you are testing the function pointer, which is true (non-zero).
And, strangely, you have a bunch of capitalized keywords.
They should be lowercase.
@coder777, He says that the open command didn't fail and yet, magically, the file didn't open either. Of course, typing a bunch of crap on your phone and then asking what's wrong with it is basically retarded, so....