I am using DEV-C++ on my windows PC;
When i try to run this simple program, it says
([Error] iostream: No such file or directory
compilation terminated)
i dont know what does it mean? anyone please tell me?
// writing on a text file
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream myfile ("example.txt");
if (myfile.is_open())
{
myfile << "This is a line.\n";
myfile << "This is another line.\n";
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
I'm sorry, I'm really new to this, still trying to read up on data files and input/output on files;
do you mean like this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// writing on a text file
#include <iostream>
#include <fstream>
usingnamespace std;
int main ()
{
ofstream myfile;
myfile.open ("example.txt");
if (myfile.is_open())
{
myfile << "This is a line.\n";
myfile << "This is another line.\n";
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
You must a problem elsewhere, and not with the program, as I copied it, compiled it and ran the code in MS Visual Studio, with no problems. Maybe you have to put a '.h' after fstream, [ example <fstream.h> ] especially if it's an older version of Dev-C++. Anyway, try that and see if it helps. Get back to me if it doesn't, and I'll try putting it in my Dev-C++
i tried putting '.h' after fstream like you said, it's still showing error.
maybe its because of my software. which one do you use? maybe I'll try that.
I am using DEV-C++ on my windows PC;
When i try to run this simple program, it says
([Error] iostream: No such file or directory
compilation terminated)
This looks like something is wrong with the configuration or installation of DevC++.
Yeah!
i figured out the problem, nothing wrong with the program. it was me, i saved the codes as a 'C source file', tried saving it as 'C++ source file' that was no problem.
Another thing is, i just started working with data files. Currently trying to do something that involves data files. As in, creating a text file; writing in the text file; reading from it; editing it;I would really appreciate if anyone could give me something that i can read up on that can help me with this.
Thanks a lot.
As for editing a file, my advice is to read the entire file into the program variables. Depending on how large/complex it is, you may use an array or better still a vector. Make the changes to the in-memory version. Then write it back to the same file when you're finished.