G
Guest
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_iterators 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_iteraters. (I didn't have the
problems
with ostream_iterators) .
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_iterator<int, ptrdiff_t> i(file), eof;
}
return 0;
}
:\source\C and C++\stlTester\initer\initer.cpp(18) :
error C2664: '__thiscall std::istream_iterator<int,int,struct
std::char_traits<int> >::std::istream_iterator<int,int,struct
std::char_traits<int> >(class std::basic_istream<int,struct std::char_t
raits<int> > &)' :
cannot convert parameter 1 from 'class std::basic_ifstream<char,struct
std::
char_traits<char> >
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.txt", 0);
if(!file) {
cout << "Cannot open file example.txt" << endl;
return 1;
}
copy(istream_iterator<int, ptrdiff_t> (file),
istream_iterator<int, ptrdiff_t>(),
inserter(a,a.begin()));
copy(a.begin(),a.end(),
ostream_iterator<int>(cout," "));
cout <<endl;
return 0;
}
f:\source\c and c++\stltester\copyio\copyio.cpp(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\copyio\copyio.cpp(25) : error C2440: 'type
cast' : cannot convert from 'class std::basic_ifstream<char,struct
std::char_traits<char> >' to 'class std::istream_iterator<int,int,struct
std::char_traits<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): +2783142235649936
More ways to contact me: http://wwp.icq.com/235649936
_________________________________________
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_iterators 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_iteraters. (I didn't have the
problems
with ostream_iterators) .
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_iterator<int, ptrdiff_t> i(file), eof;
}
return 0;
}
:\source\C and C++\stlTester\initer\initer.cpp(18) :
error C2664: '__thiscall std::istream_iterator<int,int,struct
std::char_traits<int> >::std::istream_iterator<int,int,struct
std::char_traits<int> >(class std::basic_istream<int,struct std::char_t
raits<int> > &)' :
cannot convert parameter 1 from 'class std::basic_ifstream<char,struct
std::
char_traits<char> >
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.txt", 0);
if(!file) {
cout << "Cannot open file example.txt" << endl;
return 1;
}
copy(istream_iterator<int, ptrdiff_t> (file),
istream_iterator<int, ptrdiff_t>(),
inserter(a,a.begin()));
copy(a.begin(),a.end(),
ostream_iterator<int>(cout," "));
cout <<endl;
return 0;
}
f:\source\c and c++\stltester\copyio\copyio.cpp(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\copyio\copyio.cpp(25) : error C2440: 'type
cast' : cannot convert from 'class std::basic_ifstream<char,struct
std::char_traits<char> >' to 'class std::istream_iterator<int,int,struct
std::char_traits<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): +2783142235649936
More ways to contact me: http://wwp.icq.com/235649936
_________________________________________