Hi,im having trouble with fstreams at the moment,here is my code
// read contents of file using fstream
// using the ->get() function.
// Ascii files only.
#include <iostream>
#include <fstream>
using namespace std;
main(){
fstream* file = new fstream( "myfile.txt", fstream::in);
char aSingleCharacter;
//this will read a single char from file "myfile.txt"
aSingleCharacter = (char)file->get();
// will read contents as long as variable is != EOF
while(aSingleCharacter != EOF)
{
cout << aSingleCharacter;
aSingleCharacter = (char)file->get();
}
file->close();
}
From what i understand,and its probably wrong:
when the file dreams.text is created it should be in the same folder where this code and exe is saved.But it is not there,i even created it and nothing was wrote to it.Is there a problem with the code or is the file created some were on the directory?