#include <iostream>
#include <string>
#include <fstream>
#include <cstring>
using namespace std;
int main(){
char a;
cout << "give me the filename: ";
cin >> filename;
ifstream caroll;
caroll.open(filename.c_str());
while (a=caroll.get() && !caroll.eof()){
cout << a << " ";
}
caroll.close();
}
I am getting output full of weird chars. They are like little squares filled with 2 0’s and 2 1’s.
Please turn on your compilers warning level. There’s a bug here:
This is interpreted as:
You need to add parenthesis around the assignment:
GCC warns about this.
(Note: please post code that compiles,
filenameis not declared in your sample, and you’re includingcstringwhen you should be includingstring.)