i included itreator header and declared istream_iterator using using declaration like this:
1 2 3 4 5 6 7 8 9 10 11
#include<iterator>
#include<iostream>
...
using std::istream_iterator
using std::cin;
...
int main()
{
...
istream_iterator<string> is_it( cin );
...
While compiled, the compiler complaint istream_iterator isn't a member of std
After that, i searched the internet , found that successful codes using
usingnamespace std
, then i followed that, like this
1 2 3 4 5 6 7 8 9
#include<iterator>
#include<iostream>
...
usingnamespace std;
int main()
{
...// The same...
...
}
but the problem remains.
I use Mingw, well, i don't know the version, cause when i downloaded it , i didn't notice, now i don't know how and where to find out...I doubt there is something wrong with my Mingw, it seems like it is lack of something, such as a header...Can you help me? Thanks !
If you are using Dev-C++ then your version of MinGW is outdated. You'll want to update your MinGW to the latest version. (Find where Dev-C++ put it, delete the directory, and install your new MinGW in the same place.)
You can check your MinGW version by running g++ --version from C:\MinGW\bin (assuming MinGW is installed in C:\MinGW, obviously). If it's 3.x, upgrade to 4.x.
Hi, guys, i am sorry for my slow response...
I tried the example from that link, surprisingly, it works fine. I think i'd better post my whole source file here, maybe you can help me find out.
The intention of this program is to use an ostream_iterator bound to the std::cout to write what is read from an istream_iterator bound to an ifstream object to standard output . It's really simple, right? Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include<iostream>
#include<fstream>
#include<string>
#include<stdexcept>
#include<iterator>
using namesapce std;
int main()
{
cout << "Please enter a file name which you want to copy: " << endl;
string name;
cin >> name;
ifstream input_file( name.c_str() );
istream_iterator<string> in_iter( input_file ) , eof ;
ostream_iterator<string> out_iter( cout, ' ' );
cout << "The contents of the output file are : " << endl;
while( in_iter != eof ) * out_iter ++ = * in_iter ++;
return 0;
}
using namesapce std; //ERROR: misspelling of the word namespace
ostream_iterator<string> out_iter( cout, ' ' );//ERROR in second parameter - should not be a char
should be: ostream_iterator<string> out_iter( cout, " " );//Ok - should be a char*
You might need to put in some sort of pause before return 0; command so you can see the output
I don't think that is the problem. I fixed them, well, the problem remains. The complier complains
1 2 3
istream_iterator was not declared in this scope;
ostream_iterator was not declared in this scope;
...
As i have tried , when i copy the example codes from the given link page, it works fine, doesn't that mean my compiler is all right? But now , it doesn't compile my codes , why?
According to what you said, my codes are fine except these two errors, if that is the case, where is the problem? I recommend you copy and compile the codes and tell me the result.
I think that will find out whether my compiler is all right.
Hey, i found the problem, well , it's really an embarrassment, i misspelled the "iterator" in the include statement. Sorry, guys, wasted you so much time, i would never make such mistakes again. Again, Thanks you very very much.