Question:27
Write a C++ program to read the contents of a file and display contents without spaces
Sol:
/* file: data.txt display contents of a file without spaces */ #include<iostream> #include<fstream> #include<conio.h> using namespace std; void disp() { char ch; ifstream abc; abc.open("data.txt"); //or //ifstream abc("data"); if(abc.fail()) { cout<<"Unable to open the file"<<endl; return; } while(!abc.eof()) { abc.get(ch); if(ch!=' ') cout.put(ch); } } int main() { disp(); return(0); }