I am writing a program with multiple source code files (my IDE is code blocks). I have a readBytes() function which opens an ifstream from a binary file and reads the bytes into an array. When the readBytes() function is defined in my main.cpp, it works fine. But if I try to define it in a separate source code file, it stops working! The error says "ifstream was not declared in this scope." I tried putting #include <ifstream> in my main source code, in the separate source code, and in both. No luck. Does anyone know the solution? Thanks! My code is below:
****source code in main.cpp
#include <iostream>
#include <ifstream>
void readBytes(const char*, char*, int);
int main() {
char * myarray = new char[20];
readBytes("myfile", myarray, 20);
for (int i = 0;i<20;i++) cout << myarray[i];
}
****source code in separate.cpp
#include <ifstream>
wow I feel dumb - after sweating this problem for a couple days, I post it up here, and in 15 min I spot the answer. My main.cpp also had the crucial line "using namespace std". That's what I had omitted from separate.cpp.