[Dev-C++] Second STL example has a problem...
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2003-07-10 12:44:36
|
It's annoying because the examples don't show what headers to add nor does
it say about using namespace std (I'm going with Ioannis' theory about
explicitly stating std:: in my code).
This line is causing the problem in VC++ 6.0
std::vector<std::string> StrVector(Itr, EndOfFile);
where Itr and EndOfFile are members of my class LineIterator
I'm told by the compiler that Itr cannot be converted to an unsigned int...
thoughts?
class definition:
#include <iostream>
#include <algorithm>
#include <string>
class LineIterator
{
public:
std::istream* In;
std::string Line;
bool IsValid;
/* Inlined function Read() is
used to check for a non-null
pointer and then gets user
input. If non-null input the
user has entered valid data.
*/
void Read()
{
if (In)
{
std::getline(*In, Line);
}
IsValid = (*In) ? true : false;
}
typedef std::input_iterator_tag IteratorCategory;
typedef std::string ValueType;
typedef ptrdiff_t DifferenceType;
typedef const std::string* StrPtr;
typedef const std::string& StrRef;
/// Constructor
LineIterator() : In(&std::cin), IsValid(false){}
/// Overloaded constructor.
LineIterator(std::istream& IStrmObj) : In(&IStrmObj) { Read(); }
/**
* @Group OperatorOverrides
* The operator overrides for the LineIterator class.
*/
// Operator override for the * operator.
StrRef operator*() const { return Line; }
// Override the indirection operator
StrPtr operator->() const { return &Line; }
// Override the increment operator
LineIterator operator++()
{
Read();
return *this;
}
LineIterator operator++(int)
{
LineIterator Temp = *this;
Read();
return Temp;
}
bool operator==(const LineIterator& LineItrObj) const
{
return (In == LineItrObj.In && IsValid == LineItrObj.IsValid) ||
(IsValid == false && LineItrObj.IsValid == false);
}
bool operator!=(const LineIterator& LineItrObj) const
{
return !(*this == LineItrObj);
}
// End of group.
};
_________________________________________________________________
Hotmail messages direct to your mobile phone http://www.msn.co.uk/msnmobile
|