M
malla
If I want to use istream rather than ifstream, the following program
does not work. any suggestions anyone? I want to read my data in any
given stream (and not just through a file or something). I changed my
previous code to the following, which is not
working:
#include <iostream>
#include <sstream>
#include <istream>
#include <fstream>
#include <string>
using namespace std;
class SensorAnalysis{
private:
public:
SensorAnalysis::SensorAnalysis();
void SensorAnalysis::rBuff(istream &buff);
};
SensorAnalysis::SensorAnalysis(){
}
void SensorAnalysis::rBuff(istream &buff){
cout<< "here\n";
if(buff){
string str;
while(getline(buff, str)) {
cout << str << endl;
}
buff.close();
}
else{
cout<<"retard\n";
}
}
int main()
{
SensorAnalysis sense;
istream file("1.txt");
sense.rBuff(file);
return 0;
}
does not work. any suggestions anyone? I want to read my data in any
given stream (and not just through a file or something). I changed my
previous code to the following, which is not
working:
#include <iostream>
#include <sstream>
#include <istream>
#include <fstream>
#include <string>
using namespace std;
class SensorAnalysis{
private:
public:
SensorAnalysis::SensorAnalysis();
void SensorAnalysis::rBuff(istream &buff);
};
SensorAnalysis::SensorAnalysis(){
}
void SensorAnalysis::rBuff(istream &buff){
cout<< "here\n";
if(buff){
string str;
while(getline(buff, str)) {
cout << str << endl;
}
buff.close();
}
else{
cout<<"retard\n";
}
}
int main()
{
SensorAnalysis sense;
istream file("1.txt");
sense.rBuff(file);
return 0;
}