Hello, I'm writing a program that is meant to simulate a Turing machine, and I'm currently stuck at simulating the tape. I actually think I've got it all done, but there seems to be something I missed when reading from a textual files. I've decided that the contents of the tape will be read from a textual data file, but I'm getting an error when I use ulaz<<pomz, where ulaz is of type ifstream, and pomz is a char. I first tried impleteing it in C style, with a FILE* and using fscanf, but decided that I should learn how to use the C++ variant.
The error I'm getting is this:
"error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &&,_Ty)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &&' from 'std::ifstream'"
This error appears about 100 times, on lines 13 and 21, which are ulaz << pomz.
There is also another error, which is:
"error C2676: binary '<<' : 'std::ifstream' does not define this operator or a conversion to a type acceptable to the predefined operator"
This one appears on line 13.
Here's the code of the troublesome method:
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 27 28 29 30 31 32 33
|
#include <iostream>
#include <fstream>
using namespace std;
#include "traka.h"
void Traka::ucitajTraku(char* imeDat) {
ifstream ulaz;
ulaz.open(imeDat,ios::in);
char pomz;
int i = 0;
ulaz << pomz;
while (pomz != EOF)
i++;
ulaz.close();
this->mem = new char[i+1];
ulaz.open(imeDat,ios::in);
for (int j = 0; j < i; j++) {
ulaz << pomz;
if (pomz == '\n') {
j--;
i--;
}
else
this->mem[j] = pomz;
}
this->mem[i] = '\0';
this->brslova = strlen(mem);
ulaz.close();
}
|
And here's the class definition in case it's helpful:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
class Traka {
char *mem;
int brslova;
Traka(const Traka& t) {}
Traka& operator=(const Traka& t) {}
public:
Traka() {}
void ucitajTraku(char* imeDat);
void pisi(ostream& os, int pozglave);
char operator[](int i) const;
char& vratiRef(int i);
~Traka() {
delete mem;
}
};
|
Thanks in advance for any help.