am studying a book called "STL for C++" by Leen Ammeraal. copy right 1997
I am on page 160 of 209 pages and I have to got the output right for all of
the author's examples
I had to change the headers, and one function took too many arguments, but
I got it to get the same output as the author had.
However two projects with istream_iterato rs failed to compile. I am
enclosing the
code (it is possible some ot the headers are uneccasary) to see if
if any one knows how to code modern istream_iterate rs. (I didn't have the
problems
with ostream_iterato rs) .
The following code produces a compiler error:
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <istream>
#include <vector>
#include <iterator>
using namespace std;
int main(int argc, char* argv[]) {
ifstream file("num.txt", ios::in);
int x;
if(file) {
istream_iterato r<int, ptrdiff_t> i(file), eof;
}
return 0;
}
:\source\C and C++\stlTester\i niter\initer.cp p(18) :
error C2664: '__thiscall std::istream_it erator<int,int, struct
std::char_trait s<int> >::std::istream _iterator<int,i nt,struct
std::char_trait s<int> >(class std::basic_istr eam<int,struct std::char_t
raits<int> > &)' :
cannot convert parameter 1 from 'class std::basic_ifst ream<char,struc t
std::
char_traits<cha r> >
Also the follwing code produces the following error:
// copyio.cpp : Defines the entry point for the console application.
//Taken from "STL for C++ programmers" by Leen Ammeral.
// I abandoned it because it line 22 and line 25 didn't compile
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <istream>
#include <fstream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
int main(int argc, char* argv[])
{
vector<int> a;
ifstream file("example.t xt", 0);
if(!file) {
cout << "Cannot open file example.txt" << endl;
return 1;
}
copy(istream_it erator<int, ptrdiff_t> (file),
istream_iterato r<int, ptrdiff_t>(),
inserter(a,a.be gin()));
copy(a.begin(), a.end(),
ostream_iterato r<int>(cout," "));
cout <<endl;
return 0;
}
f:\source\c and c++\stltester\c opyio\copyio.cp p(5) : warning C4652: compiler
option 'Generate Browser Info' inconsistent with precompiled header; current
command-line option will override that defined in the precompiled header
F:\source\C and C++\stlTester\c opyio\copyio.cp p(25) : error C2440: 'type
cast' : cannot convert from 'class std::basic_ifst ream<char,struc t
std::char_trait s<char> >' to 'class std::istream_it erator<int,int, struct
std::char_trait s<int> >'
No constructor could take the source type, or constructor overload
resolution was ambiguous
Error executing cl.exe.
_______________ _______________ ___________ Mitchell McNurlin ICQ#:235649936
Current ICQ status: SMS: (Send an SMS message to my ICQ): +27831422356499 36
More ways to contact me: http://wwp.icq.com/235649936
_______________ _______________ ___________