[ create a new paste ] login | about

Link: http://codepad.org/G3Chty9K    [ raw code | output | fork ]

C++, pasted on Jun 10:
#include<string>
#include<iostream>
#include<fstream>
#include<vector>
#include<iterator>

class Line
{
  std::string data;

public:
  friend std::istream& operator>>(std::istream& inputStream, Line& line)
  {
    std::getline(inputStream, line.data);
    return inputStream;
  }

  operator std::string()
  {
    return data;
  }
};

int main(int argc, char* argv[])
{
  std::fstream file("filename.txt", std::fstream::in | std::fstream::out);
  std::vector<std::string> lines;

  // error is in one of these lines
  std::copy(
    std::istream_iterator<Line>(file),
    std::istream_iterator<Line>(),
    std::back_inserter(lines));
}


Output:
1
2
3
4
5
6
7
/usr/local/lib/gcc/i686-pc-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algobase.h: In static member function 'static _OI std::__copy<<anonymous>, <template-parameter-1-2> >::copy(_II, _II, _OI) [with _II = std::istream_iterator<Line, char, std::char_traits<char>, int>, _OI = std::back_insert_iterator<__gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, bool <anonymous> = false, <template-parameter-1-2> = std::input_iterator_tag]':
/usr/local/lib/gcc/i686-pc-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algobase.h:317:   instantiated from '_OI std::__copy_aux(_II, _II, _OI) [with _II = std::istream_iterator<Line, char, std::char_traits<char>, int>, _OI = std::back_insert_iterator<__gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >]'
/usr/local/lib/gcc/i686-pc-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algobase.h:326:   instantiated from 'static _OI std::__copy_normal<<anonymous>, <anonymous> >::copy_n(_II, _II, _OI) [with _II = std::istream_iterator<Line, char, std::char_traits<char>, int>, _OI = std::back_insert_iterator<__gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, bool <anonymous> = false, bool <anonymous> = false]'
/usr/local/lib/gcc/i686-pc-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algobase.h:387:   instantiated from '_OutputIterator std::copy(_InputIterator, _InputIterator, _OutputIterator) [with _InputIterator = std::istream_iterator<Line, char, std::char_traits<char>, int>, _OutputIterator = std::back_insert_iterator<__gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >]'
t.cpp:34:   instantiated from here
Line 269: error: no match for 'operator=' in '__result. std::back_insert_iterator<_Container>::operator* [with _Container = __gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >]() = __first. std::istream_iterator<_Tp, _CharT, _Traits, _Dist>::operator* [with _Tp = Line, _CharT = char, _Traits = std::char_traits<char>, _Dist = int]()'
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: