G
George
Hi All,
I'm trying to learn c++/stl. I'd like a fancy way to read lines of an
ascii file into vector of stringbufs. I made a first attempt, but the
compiler complains about private constructors in streambuf.
I'd like to use algorithms instead of a loop, but I don't know if that
is possible. Any ideas?
Thanks in advance.
--------------------------------------------------
#include <iostream>
#include <fstream>
#include <iterator>
#include <sstream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
istream& operator>> (istream& is, stringbuf& sb)
{
is.get(sb);
return is;
}
int main()
{
vector<stringbuf> v;
ifstream f;
f.open(__FILE__);
cout << __FILE__ << endl;
istream_iterator<stringbuf> istart(f),iend;
v.insert(v.begin(),istart,iend);
cout << v.size() << endl;
return 0;
}
I'm trying to learn c++/stl. I'd like a fancy way to read lines of an
ascii file into vector of stringbufs. I made a first attempt, but the
compiler complains about private constructors in streambuf.
I'd like to use algorithms instead of a loop, but I don't know if that
is possible. Any ideas?
Thanks in advance.
--------------------------------------------------
#include <iostream>
#include <fstream>
#include <iterator>
#include <sstream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
istream& operator>> (istream& is, stringbuf& sb)
{
is.get(sb);
return is;
}
int main()
{
vector<stringbuf> v;
ifstream f;
f.open(__FILE__);
cout << __FILE__ << endl;
istream_iterator<stringbuf> istart(f),iend;
v.insert(v.begin(),istart,iend);
cout << v.size() << endl;
return 0;
}